Link to home
Start Free TrialLog in
Avatar of keithwilson1
keithwilson1Flag for United States of America

asked on

Merge two rows in SQL

Assuming I have a table containing the following information:

FK | Field1 | Field2
=====================
1  | ABC    | *NULL*
2  | *NULL* | DEF
is there a way I can perform a select on the table to get the following

FK | Field1 | Field2
=====================
2  | ABC    | DEF
Thanks
Avatar of Sean Stuber
Sean Stuber

you haven't specified a grouping criteria, so something like this will work for your sample data and results, but may need to be changed for an expanded data set


select max(fk) fk, max(field1) field1, max(field2) field2 from yourtable
Avatar of keithwilson1

ASKER

GROUP BY
    FK;

Group by FK value 1 and 2
Giving a new row with 2 in the FK field

The table will have 450 rows. 1 and 2 in the FK field with a StudentID.  Sorry for not specifying the StudentID earlier.

StudentID |FK | Field1 | Field2
=====================
A0203340 |1  | ABC    | *NULL*
A0203340 |2  | *NULL* | DEF
is there a way I can perform a select on the table to get the following

StudentID |FK | Field1 | Field2
=====================
A0203340 |2  | ABC    | DEF
Grouping is done by StudentID and FX.
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial