这是表一中的一些数据(人)
Person Table
person_ID | Name | Address
1 | JC | 303 Main Street
2 | NM | 444 Nowhere Drive
和表二(属性)
Attribute table
person_ID | attribute
1 | dog
1 | cat
2 | bearded
当我加入表格时,我得到以下视图:
person_id | name | attribute
1 | JC | dog
1 | JC | cat
2 | NM | bearded
它们是左表中的重复行。它包含相同的 person_id 等。我想将前两个结果组合成一行。像这样:
person_id | name | attribute | attribute
1 | JC | dog cat
2 | NM | bearded NULL
或这个:
person_id | name | attribute
1 | JC | dog, cat
2 | NM | bearded
这是我尝试过的一些代码:
SELECT person.*,Attribute.att FROM `person`,`Attribute`
WHERE person.`person_id` = Attribute.person_id
AND name = "" group by person_id
左连接
Select * from person AS P
LEFT JOIN Attribute AS N
ON P.person_id = N.person_id
还尝试了内部连接。