Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

MySQL / PHP help

Hi All,

I have the following MySQL table

ID    Customer     Contact
1     ABC Ltd         John Smith
2     ABC Ltd         Joe Bloggs
3     XYZ Ltd         Tom Jones
4     XYZ Ltd         Andy Murray

Open in new window


I need to get this into an new table as

ID    Customer     Contact
1     ABC Ltd         John Smith,Joe Bloggs
2     XYZ Ltd         Tom Jones,Andy Murray

Open in new window



Any suggestions?
0
detox1978
Asked:
detox1978
  • 2
1 Solution
 
GaryCommented:
INSERT INTO table2 SELECT id,customer,GROUP_CONCAT(contact) FROM table1 GROUP BY contact

Open in new window

0
 
detox1978Author Commented:
I just needed to change the GROUP BY to customer and it worked perfectly.  Thanks
0
 
GaryCommented:
Oops yes
0
 
Ray PaseurCommented:
Any MySQL book by Vikram Vaswani will give you a good foundation.  I have an older one (MySQL 4) and it still covers almost everything I need to do!
http://mysql-tcr.com/book/
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now