Basheer Raad
Basheer Raad

Reputation: 21

Oracle Query that fetches one row per each _id

I have a table like :

ID  | Val |  Kind
----------------------
 1  |  a  |   2
 2  |  b  |   1
 3  |  c  |   4
 3  |  c  |   33

and I need to fetch one row per each id in Oracle SQL. any ideas?

Upvotes: 0

Views: 2081

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270483

You can use row_number() to enumerate the rows. For an arbitrary row:

select t.*
from (select t.*,
             row_number() over (partition by id order by id) as seqnum
      from t
     ) t
where seqnum = 1;

As I point out in a comment, though, this is unnecessary based on the data in your question. The ids are already unique.

Upvotes: 2

Related Questions