0

有谁知道如何使用列中表中的多个值进行 mysql 内部连接,我的意思是:

t_1: id_t1 | name
           001 | name_value

t_2: id_t2 | value
           020 | value1
           030 | value2
           040 | value3
           050 | value4

t1_t2: id_t1 | id_t2
              001 | 020
              001 | 030
              001 | 050

然后,一个返回我的查询,例如:

id_t1 | name           | values_t_2
    001 | name_value | value1, value2, value4

如果有人能告诉我这样做的方法,我将不胜感激。

4

1 回答 1

4
SELECT
    t1.id_t1,
    t1.name,
    GROUP_CONCAT(t2.value SEPARATOR ', ') AS values_t_2
FROM
    t_1 t1
    INNER JOIN t1_t2 t1t2 ON (t1.id_t1 = t1t2.id_t1)
    INNER JOIN t_2 t2 ON (t1t2.id_t2 = t2.id_t2)
GROUP BY
    t1.id_t1
于 2013-02-19T21:19:22.373 回答