Reputation: 23
I have a sql query that returns duplicate rows. I want refine the result so that the duplicate rows are limited to 5. How can I do this ?
Upvotes: 1
Views: 497
Reputation: 3801
This will work pretty generally, but it assumes your DBMS supports ROW_NUMBER(). You should tag your DBMS, better solutions may be possible ... or this one might not even work.
SELECT All,
of,
your,
columns
FROM (SELECT T1.*
ROW_NUMBER() OVER
( PARTITION BY All,
Of,
Your,
Columns
) AS rn
FROM Table1 T1
) TMP
WHERE rn <= 5;
Upvotes: 1