what I’m trying to do is copy some columns to other table by obj_id
UPDATE obj_object
INNER JOIN obj_extract as address ON (obj_object.id = address.obj_id AND address.category_id = 1)
INNER JOIN obj_extract as city ON (obj_object.id = city.obj_id AND city.category_id = 2)
INNER JOIN obj_extract as country ON (obj_object.id = country.obj_id AND country.category_id = 3)
INNER JOIN obj_extract as phone ON (obj_object.id = phone.obj_id AND phone.category_id = 4)
SET obj_object.address = address.info,
obj_object.city = city.info,
obj_object.country = country.info,
obj_object.phone = phone.info
But some obj_extract rows have same category_id, I need to count if record containing same obj_id have more than one row with same category_id if yes, I need to concat these entries and copy to obj_object table column. Table example:
+----+--------------+---------+---------+
| ID | category_id | info | obj_id |
+----+--------------+---------+---------+
| 1 | 1 | test | 2 |
+----+--------------+---------+---------+
| 2 | 1 | test1 | 2 |
+----+--------------+---------+---------+
| 3 | 2 | test2 | 2 |
+----+--------------+---------+---------+
I need to get like:
obj_object.address = 'test - test1', // // value from address.info
obj_object.city = 'test2', // value from city.info
You need to look into using
GROUP_CONCAT:Good luck.