Dylan Reynolds
Dylan Reynolds

Reputation: 11

Concatenate multiple rows into one row (But not a as a string)

I have a table that looks like this:

 iD     PhoneNumber    EmailAddress
 1       06543635463    NULL
 1       NULL           [email protected]
 2       NULL           [email protected]
 2       0298754355     NULL
 3       0543280545     NULL

And I'm tryong to concatenate the rows so they look like this:

id    PhoneNumber      EmailAddress
1     06543635463      [email protected]
2     0298754355       [email protected]
3     0543280545       NULL

Any help would be appreciated. Thanks so much.

Upvotes: 0

Views: 51

Answers (1)

Lamak
Lamak

Reputation: 70638

That's not a concatenation, it's a simple aggregation. Sounds like you could use MIN or MAX:

SELECT id,
       MAX(PhoneNumber) PhoneNumber,
       MAX(EmailAddress) EmailAddress
FROM dbo.YourTable
GROUP BY id;

Upvotes: 7

Related Questions