How do I combine multiple rows into one row?
20 pts.
0
Q:
How do I combine multiple rows into one row?
I have a table

Col1 Col2 Col3 Col4 Col5
----- ------ ------ ----- ------
1 abc NULL NULL NULL
1 NULL def NULL NULL
1 NULL NULL ghi NULL
1 NULL NULL NULL jkl

I want:

Col1 Col2 Col3 Col4 Col5
----- ------ ------ ----- ------
1 abc def ghi jkl

At first I thougt I could use pivot which I'm not sure how to do that but then I started doubting that. Any help would be great!

Thanks~!
ASKED: Feb 18 2009  11:37 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
46795 pts.
0
A:
 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0
  • AddThis Social Bookmark Button
One method is to use MAX on all the columns that aren't your ID field.

SELECT Col1, max(Col2), max(Col3), max(Col4), max(Col5)
FROM YourTable
GROUP BY Col1
Last Answered: Feb 19 2009  3:04 AM GMT by Mrdenny   46795 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Carlosdl   29855 pts.  |   Feb 18 2009  11:39PM GMT

What DBMS are you using ? what version ?

 

Cathryn   20 pts.  |   Feb 19 2009  1:07AM GMT

Sorry - SQL 2005

 
0