72

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

说我的桌子是;

TableA TableB TableC

我希望加入A-B,但也B-C都由这个我称之为共同的共同领域。

我已经加入了两个这样的表;

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

如何添加第三个?

4

5 回答 5

134
select *
from
    tableA a
        inner join
    tableB b
        on a.common = b.common
        inner join 
    TableC c
        on b.common = c.common
于 2012-08-06T08:02:04.113 回答
16

只是做同样的事情,然后是 TableC

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
于 2012-08-06T08:03:37.247 回答
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
于 2012-08-06T08:03:24.777 回答
7

试试下面的代码

select * from TableA A 
inner join TableB B on A.Column=B.Column 
inner join TableC C on A.Column=C.Column
于 2012-08-06T08:05:54.143 回答
3

试试这个:

SELECT * FROM TableA
JOIN TableB ON TableA.primary_key = TableB.foreign_key 
JOIN TableB ON TableB.foreign_key = TableC.foreign_key
于 2014-04-21T06:01:26.680 回答