I have 3 tables below I'm trying to write a group_concat
statement for the "item" column in the table cart_session
TABLE products
id name
------------------------
123 | car
456 | boat
789 | house
--------------------------------
TABLE cart_items
pid session
----------------------
123 | ABCD
456 | ABCD
789 | EFGH
----------------------------------
TABLE cart_session
id item
----------------------------
ABCD | car,boat
EFGH | house
您可以使用update / join语法,如下所示:
另一个选项使用相关的子查询:
This is slightly different: this query would assign a
null
value to rows incart_session
that have no match in the other tables, while the first query leaves such rows intact.