Reputation: 6610
I have three tables I wish to inner join by a common column between them.
Say my tables are;
TableA TableB TableC
I wish to join A-B
, but then also B-C
all by this common field I will call common.
I have joined two tables like this;
dbo.tableA AS A INNER JOIN dbo.TableB AS B
ON A.common = B.common
How do I add the third one?
Upvotes: 72
Views: 235989
Reputation: 51494
select *
from
tableA a
inner join
tableB b
on a.common = b.common
inner join
TableC c
on b.common = c.common
Upvotes: 135
Reputation: 6918
try the following code
select * from TableA A
inner join TableB B on A.Column=B.Column
inner join TableC C on A.Column=C.Column
Upvotes: 7
Reputation: 399
try this:
SELECT * FROM TableA
JOIN TableB ON TableA.primary_key = TableB.foreign_key
JOIN TableB ON TableB.foreign_key = TableC.foreign_key
Upvotes: 3
Reputation: 26937
Just do the same thing agin but then for 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
Upvotes: 17
Reputation: 1825
dbo.tableA AS A INNER JOIN dbo.TableB AS B
ON A.common = B.common INNER JOIN TableC C
ON B.common = C.common
Upvotes: 8