我在mysql中有两个表:
table1
id | name
=============
11 | AAA
22 | BBB
33 | CCC
table2
id | type1 | type2 | type3
======================================
1 | 22 | 11 | 33
2 | 11 | 22 |
3 | 33 | | 11
下面是我使用的MYSQL查询:
SELECT table2.type1, table1.name
FROM table2, table1
WHERE table2.type1=table1.id
要么
SELECT table2.type1, table1.name FROM table2
inner join table1 on table2.type1=table1.id
有这个结果:
type1 | name
================
22 | BBB
11 | AAA
33 | CCC
我怎么能有这个:???
id | type1 | name | type2 | name | type3 | name
=========================================================================
1 | 22 | BBB | 11 | AAA | 33 | CCC
2 | 11 | AAA | 22 | BBB | |
3 | 33 | CCC | | | 11 | AAA