Reputation: 5525
I have a query that returns two lines per ID
. I would like to be able to merge these into one single row, based on the ID
.
There will only ever be two rows per ID
. As in the example below, one row will only ever contain ColumnA
and the other row will contain ColumnB
.
So this is a simplified version of how the data looks at the moment:
And this is how I would like it to be, although I'm not entirely sure how to go about it:
Upvotes: 2
Views: 1328
Reputation: 35780
You can do this by aggregation:
select ID, max(ColumnA) ColumnA, max(ColumnB) ColumnB
from TableName
group by ID
Upvotes: 6