Inner Joining three tables
SqlSql ServerSql Problem Overview
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?
Sql Solutions
Solution 1 - Sql
select *
from
tableA a
inner join
tableB b
on a.common = b.common
inner join
TableC c
on b.common = c.common
Solution 2 - Sql
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
Solution 3 - Sql
dbo.tableA AS A INNER JOIN dbo.TableB AS B
ON A.common = B.common INNER JOIN TableC C
ON B.common = C.common
Solution 4 - Sql
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
Solution 5 - Sql
try this:
SELECT * FROM TableA
JOIN TableB ON TableA.primary_key = TableB.foreign_key
JOIN TableB ON TableB.foreign_key = TableC.foreign_key