JTirr
JTirr

Reputation: 45

Combining rows in SQL Server

I'm trying to combine rows in SQL Server.

Assume I have a table like:

  C1 |  C2  | C3
  1  |  A   | 
  1  |      | 
  1  |      |  B
  2  |  A   |  
  2  |      |  C

And I want to end up with:

  C1 |  C2  | C3
  1  |  A   |  B
  2  |  A   |  C

Any way I can do this with one query?

At the moment I'm parsing the data manually with c#, but it's slow, and I can't limit the number of rows that are returned easily.

Thanks in advance!

Upvotes: 4

Views: 616

Answers (1)

Martin Smith
Martin Smith

Reputation: 453278

For your example data

SELECT C1,
       MAX(C2) AS C2,
       MAX(C3) AS C3
FROM   YourTable
GROUP  BY C1 

SQL Fiddle

Upvotes: 11

Related Questions