How do I combine multiple rows into one row?

35 pts.
Tags:
SQL
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~!

Answer Wiki

Thanks. We'll let you know when a new response is added.

One method is to use MAX on all the columns that aren’t your ID field.

<pre>SELECT Col1, max(Col2), max(Col3), max(Col4), max(Col5)
FROM YourTable
GROUP BY Col1</pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    What DBMS are you using ? what version ?
    83,215 pointsBadges:
    report
  • Cathryn
    Sorry - SQL 2005
    35 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: