我有2张桌子
表1 :
ID Name
1 OS
2 Harddisk
3 RAM
4 WINDOWS
5 LINUX
6 SOLARIS
7 MAC
8 UNIX
9 DCCI
表2 :
ID Table1_ID Table1_component
1 1 4
2 1 5
3 1 6
4 1 7
5 1 8
6 1 9
我想加入上面的两个表,我需要输出为
Table1_ID Table1_component
OS Windows
OS Linux
OS SOLARIS
OS MAC
OS UNIX
OS DCCI
请帮助我,而不是Table 2
中的号码,我需要Table1
答案 0 :(得分:1)
您需要在Table1
上加入两次以获得结果:
select t1.name as table1_id,
c.name as Table1_component
from table1 t1
inner join table2 t2
on t1.id = t2.table1_id
inner join table1 c
on t2.Table1_component = c.id