我有两张桌子:
表1:
- id
- 姓名
- table2_id1
- table2_id2
- table2_id3
表2:
- id
- 姓名
表1:
id | name | table2_id1 | table2_id2 | table2_id3
1 | blabla | 1 | 2 | 3
2 | blabla2 | 2 | 3 | 1
表2:
id | name
1 | aaa
2 | bbb
3 | ccc
我想在Table1中显示一个名称,并从Table2中显示多个名称,这些名称已加入,例如:
*blabla | aaa | bbb | ccc*
我希望你明白我的意思。
编辑:
我试过这样的事情:
SELECT Table1.name, Table2.name, Table2.name, Table2.name<BR>
FROM Table1 JOIN Table2 ON<BR>
答案 0 :(得分:0)
SELECT a.name, b.name, c.name, d.name
FROM Table1 a, Table2 b, Table2 c, Table2 d
WHERE a.table2_id1 = b.id
AND a.table2_id2 = c.id
AND a.table2_id3= d.id
答案 1 :(得分:0)
您可以使用左连接查询:
SELECT a.name as "name", b.name as "table2_id1_name", c.name as "table2_id2_name", d.name as "table2_id3_name"
FROM Table1 a
LEFT JOIN Table2 b ON (a.table2_id1 = b.id)
LEFT JOIN Table2 C ON (a.table2_id2 = c.id)
LEFT JOIN Table2 d ON (a.table2_id3= d.id)
希望它按预期工作。 :)