Oracle SQL query to identify records that belong to the same primary record.
Posted on 2011-03-09
I have a table with the following data:
I'm looking to number records base on their ID so I can then create one record per ID.
TYPE column shouldn't be the driving factor in numbering records but rather change in the ID number. So first step is to number the records with the same ID:
ID TYPE POSITION
0100001 A 1
0100001 B 2
0100001 C 3
0100002 A 1
0100002 C 2
After I have records numbered I can use the following to create one record per ID.
select id,type,position (subquery where id=id and position=2),(subquery where id=id and position=3) from my_table where position=1;
ID TYPE POSITION SUBQUERY1 SUBQUERY2
0100001 A 1 B C
0100002 A 1 C