Reputation: 5545
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
Upvotes: 1
Views: 119
Reputation: 530
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
Upvotes: 4