I have a table like this:
ID | Val | Kind
----------------------
1 | 1337 | 2
2 | 1337 | 1
3 | 3 | 4
4 | 3 | 4
I want to make a SELECT
that will return just the first row for each Val
, ordering by Kind
.
Sample output:
ID | Val | Kind
----------------------
2 | 1337 | 1
3 | 3 | 4
How can I build this query?
Best Answer
This solution also uses
keep
, butval
andkind
can also be simply calculated for each group without a subquery:dbfiddle here
KEEP…FIRST and KEEP…LAST are an Oracle-specific feature of aggregates — you can read about then here in the Oracle docs, or on ORACLE_BASE: