I have a table in a db that has an int field, a non-unique id field plus others. I need to sort by the int field then get the top X distinct id fields.
So for example if these are my table values (sorted by the intfld):
id intfld
CC 1
AA 2
CC 3
AA 4
FF 4
OO 5
EE 6
KK 6
And I wanted the top 3 id’s the returned values would be CC,AA,FF.
I tried distinct and group by but I don’t think they will work. Maybe I’m missing something obvious since I don’t work in SQL a lot.
Can I do this with a sql statement?
Thanks.
Edit: I’m using Oracle.
This should get you on the right track: