Solved

MySQL / PHP help

Posted on 2014-12-13
4
130 Views
Last Modified: 2014-12-14
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
Comment
Question by:detox1978
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
INSERT INTO table2 SELECT id,customer,GROUP_CONCAT(contact) FROM table1 GROUP BY contact

Open in new window

0
 
LVL 2

Author Closing Comment

by:detox1978
Comment Utility
I just needed to change the GROUP BY to customer and it worked perfectly.  Thanks
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Oops yes
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
change name file before record in server 5 24
Php Array Diff 3 26
while loop in html mail format 5 32
wordpress issue 2 15
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now