0

How can I group multiple rows of data?

My data structure is similar to:

ID        NAME       PhoneNo
1         Jon        8798765
2         Jon        3134684
3         Adams      7968434
4         Phil       3435435
5         Thomas     6734354
6         Jon        2343545
7         Jeff       3435424
8         Adams      3434354

I need to use SQL to group the information so I get something like this:

ID        NAME       PhoneNo
1         Jon        8798765,3134684,2343545
3         Adams      7968434,3434354
4         Phil       3435435
5         Thomas     6734354
7         Jeff       3435424

See what I did there? I de-duplicated and added all the phone numbers on the same field, comparing the names: Same name= same person, so put all the names on the same cell. I'm currently using MS access, but I guess any other variant could work (I can find the equivalency)

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • I agree with Gord ... but wish to add that your field `ID` doesn't appear to add any value, so it doesn't belong in the result. If it IS supposed to add value, then you had better think about what will happen to `2`, '6', '8', etc. – Smandoli Jan 02 '14 at 20:25

1 Answers1

0

What you are looking for is mySQL function GROUP_CONCAT

If you are in Access, just use some kind of Macro inspired by this: is there a group_concat function in ms-access? or for MSSQL Emulating MySQL’s GROUP_CONCAT() Function in SQL Server 2005

There is a Question, what are you really need.

Community
  • 1
  • 1
MartinB
  • 456
  • 1
  • 3
  • 5