Skip to content
Advertisement

How can I concatenate field values together from other records in same table?

I have a simple table as below in MySQL. All I want to do is group records by PARENT ID and concatenate ATTRIBUTE records for that PARENT ID into the TYPE=’SIMPLE’ record.

UNIQUE ID TYPE Parent ID Attribute
MYID1 SIMPLE MYID1
MYID2 VARIANT MYID1 WHITE
MYID3 VARIANT MYID1 BLUE

So the result would be;

UNIQUE ID TYPE Parent ID Attribute
MYID1 SIMPLE MYID1 WHITE, BLUE
MYID2 VARIANT MYID1 WHITE
MYID3 VARIANT MYID1 BLUE

How would I go about this?

Advertisement

Answer

Used GROUP_CONCAT very successfully

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement