Reputation: 77
I have the following table and records
How do I return all record and top 1 record where CUSTID appears more than once.
The result should like like
CUSTID ORDERID ORDERDATE ITEMPRICE
50 1 5/10/2019 10
150 2 5/10/2019 11
51 3 5/10/2019 50
Distinct CUSTID isn't working as I need to display all the columns. Appreciate any help.
Upvotes: 0
Views: 46
Reputation: 32003
it seems you need row_number()
select a.* from
(select *,row_number()over(partition by custid order by itemprice desc)rn
from table_name
) a where a.rn=1
Upvotes: 1