1
什麼,我試圖做的是複製一些列其他表由obj_id
CONCAT列和複製到其他表的MySQL
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
但有些obj_extract
行具有相同category_id
,我需要的,如果含有相同的記錄數obj_id
有多條同一行category_id
如果有,我需要concat
這些條目並複製到obj_object
表列。表例如:
+----+--------------+---------+---------+
| ID | category_id | info | obj_id |
+----+--------------+---------+---------+
| 1 | 1 | test | 2 |
+----+--------------+---------+---------+
| 2 | 1 | test1 | 2 |
+----+--------------+---------+---------+
| 3 | 2 | test2 | 2 |
+----+--------------+---------+---------+
我需要這樣的:
obj_object.address = 'test - test1', // // value from address.info
obj_object.city = 'test2', // value from city.info
你想得到什麼輸出? – Walter
@RubberDucky編輯了我的問題 – DDD889