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
精彩评论