anonymous anonymous - 25 days ago 8
SQL Question

Duplicate records in one row

I have the following table

ID DEGREE DEGREE1 DEGREE2
1 BS
1 MS
1 PHD
2 BA
2 MA


I'm expecting to get the following results

ID DEGREE DEGREE1 DEGREE2
1 BS MS PHD
2 BA MA

Answer

Simple aggregration and max should do it..

SELECT ID, max(Degree) degree, max(Degree1) degree1, max(Degree2) Degree2
FROM table
GROUP BY Id

(must be a C/java programmer 0 based degree even though they have 3.)

This does assume there will only be 1 degree per row / id.