内部加入三张桌子

时间:2012-08-06 08:00:30

标签: sql sql-server

我有三个表,我希望通过它们之间的公共列进行内连接。

说我的桌子是;

TableA TableB TableC

我希望加入A-B,然后B-C加入dbo.tableA AS A INNER JOIN dbo.TableB AS B ON A.common = B.common 这个共同领域,我会称之为共同。

我加入了两张这样的表格;

{{1}}

如何添加第三个?

5 个答案:

答案 0 :(得分:110)

select *
from
    tableA a
        inner join
    tableB b
        on a.common = b.common
        inner join 
    TableC c
        on b.common = c.common

答案 1 :(得分:15)

再做同样的事情,然后再做表C

SELECT *
FROM dbo.tableA A 
INNER JOIN dbo.TableB B ON A.common = B.common
INNER JOIN dbo.TableC C ON A.common = C.common

答案 2 :(得分:8)

dbo.tableA AS A INNER JOIN dbo.TableB AS B
ON A.common = B.common INNER JOIN TableC C
ON B.common = C.common

答案 3 :(得分:6)

尝试以下代码

select * from TableA A 
inner join TableB B on A.Column=B.Column 
inner join TableC C on A.Column=C.Column

答案 4 :(得分:3)

试试这个:

SELECT * FROM TableA
JOIN TableB ON TableA.primary_key = TableB.foreign_key 
JOIN TableB ON TableB.foreign_key = TableC.foreign_key