yuzirui yuzirui - 26 days ago 6
MySQL Question

How can I merge 2 or more similar mysql row?

I have table tables in MySQL named "temporarytransaction" ans "tbltransaction"

temporarytransaction and tbltransaction has 3 columns named "customer", "service rendered" and "date"

so for example temporarytransaction has 3 values

Nathan | Men's Cut | 2017-09-23

Nathan | Nail Art | 2017-09-23

Nathan | Massage | 2017-09-23

what I need to do was merge or concat the "service rendered" in the tbltransaction.
is it possible to save it like this in tbltransaction?

Nathan | Men's Cut,Nail Art,Massage | 2017-09-23

I had try this but it doesn't save that way

INSERT INTO tbltransaction (customer,service,date) SELECT customer,service,date FROM temporarytransaction;";

Answer Source

You could aggregate the service values with group_concat:

INSERT INTO tbltransaction (customer,service,date)
SELECT      customer, GROUP_CONCAT(service SEPARATOR ','), date 
FROM        temporarytransaction
GROUP BY    customer, date