Inner Joining three tables

SqlSql Server

Sql 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWilliamView Question on Stackoverflow
Solution 1 - SqlpodiluskaView Answer on Stackoverflow
Solution 2 - SqlBazzzView Answer on Stackoverflow
Solution 3 - SqlArkiliknamView Answer on Stackoverflow
Solution 4 - SqlRam SinghView Answer on Stackoverflow
Solution 5 - SqlOmar FarukView Answer on Stackoverflow