Reputation: 3
ID ID1 Name
111 11 A
111 11 AA
222 12 B
222 13 C
I have a above table and I want the result as below.
ID ID1 Name
111 11 A
111 11 AA
222 12 B
The basic idea is that when ID and ID1 have same row values then it should be visible as it is and when the ID row values is same and ID1 row values are different then it should chose the above one.
Upvotes: 0
Views: 65
Reputation: 60482
This matches your result and description, returning all rows with the lowest ID1
per ID
:
SELECT *
FROM mytable
QUALIFY
RANK()
OVER (PARTITION BY ID
ORDER BY ID1) = 1
Upvotes: 1