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?
This question is related to
sql
sql-server
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
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
dbo.tableA AS A INNER JOIN dbo.TableB AS B
ON A.common = B.common INNER JOIN TableC C
ON B.common = C.common
try this:
SELECT * FROM TableA
JOIN TableB ON TableA.primary_key = TableB.foreign_key
JOIN TableB ON TableB.foreign_key = TableC.foreign_key
Source: Stackoverflow.com