我想做一个SELECT
有table A
:
table_a:
╔══════════╦════════╗
║ GROUP_ID ║ NAME ║
╠══════════╬════════╣
║ 1 ║ Tom ║
║ 2 ║ Frank ║
║ 3 ║ Shilla ║
║ 1 ║ Scully ║
║ 1 ║ Jen ║
╚══════════╩════════╝
table_b:
╔════╦════════════╗
║ ID ║ GROUP_NAME ║
╠════╬════════════╣
║ 1 ║ Troopers ║
║ 2 ║ Clubs ║
║ 3 ║ Mavericks ║
╚════╩════════════╝
现在,我想显示给定成员名称的组:
SELECT GROUP_NAME,GROUP_CONCAT(table_a.NAME) MEMBERS
FROM table_a
JOIN table_b ON table_a.GROUP_ID = table_b.ID
WHERE
table_a.NAME = 'Scully'
我想得到这个:
╔════════════╦════════════════╗
║ GROUP_NAME ║ MEMBERS ║
╠════════════╬════════════════╣
║ Troopers ║ Tom,Scully,Jen ║
╚════════════╩════════════════╝
为什么这个查询不起作用?