开发者

DISTINCT in a SQL Server 2005 query

How can I add a distinct to the following query :

SELECT TOP(30) X.ID ,ROW_NUMBER() OVER开发者_开发百科 (ORDER BY Create DESC) AS LIMIT 
FROM X  INNER JOIN Y ON X.ID = Y.ID  

as for now I get a lot of multiple records


Try something like this:

WITH CTE AS
(
SELECT DISTINCT TOP(30) X.ID, X.CREATE FROM X  INNER JOIN Y ON X.ID = Y.ID
)
SELECT *, ROW_NUMBER() OVER (ORDER BY Create DESC) AS LIMIT
FROM CTE

You must insert CREATE in your query

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜