简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM