The inner join of three tables

I have three tables that I want to add to the inner join by a common column between them.

Say my tables:

TableA TableB TableC 

I want to join AB , but then also BC all this common field I will call common.

I joined the two tables as follows:

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

How to add a third?

+59
sql sql-server
Aug 6 '12 at 8:00
source share
6 answers
 select * from tableA a inner join tableB b on a.common = b.common inner join TableC c on b.common = c.common 
+113
Aug 6 2018-12-12T00
source share

Just do the same, 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 
+15
Aug 6 2018-12-12T00:
source share
 dbo.tableA AS A INNER JOIN dbo.TableB AS B ON A.common = B.common INNER JOIN TableC C ON B.common = C.common 
+8
Aug 6 2018-12-12T00:
source share

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 
+6
Aug 6 2018-12-12T00:
source share

try the following:

 SELECT * FROM TableA JOIN TableB ON TableA.primary_key = TableB.foreign_key JOIN TableB ON TableB.foreign_key = TableC.foreign_key 
+3
Apr 21 '14 at 6:01
source share

CREATE TABLE Country ([Countrycode_pk] int Primary Key, [Country_name] varchar)

insert Country values ​​(Countrycode_pk, Country_name) ('123', 'India') insert Country values ​​(Countrycode_pk, Country_name) ('112', 'Austrailia') into Country values ​​(Countrycode_pk, Country_name) ('345', 'Pakistan ')

CREATE TABLE State ([Statecode_pk] int Primary key, [state_name] varchar, [Countrycode_fk] int)

insert values ​​('444', 'karnataka', '123') into the state (Statecode_pk, state_name, Countrycode_fk) insert values ​​('478', 'Andhra', '123') into the state (Statecode_pk, state_name, Countrycode_fk) state values ​​(Statecode_pk, state_name, Countrycode_fk) ('200', 'Tamil Nadu,' 123 ') are inserted into the state (Statecode_pk, state_name, Countrycode_fk) values ​​(' 333 ',' Queensland ',' 112 ') are inserted into the State Values ​​( Statecode_pk, state_name, Countrycode_fk) ("233", "New South Wales", "112") are inserted into state values ​​(Statecode_pk, state_name, Countrycode_fk) ("788", "Islamabad", "345")

CREATE TABLE City ([Citycode_pk] int Primary key, [City_name] varchar, [statecode_fk] int)

paste into the city (Citycode_pk, City_name, statecode_fk) values ​​('888', 'bengalore', '444') insert into city (Citycode_pk, City_name, statecode_fk) values ​​('990', 'Managlore', '444') paste into city ​​values ​​(Citycode_pk, City_name, statecode_fk) ('678', 'Mysore', '444') are inserted into city values ​​(Citycode_pk, City_name, statecode_fk) ('555', 'Hubli', '444') are inserted into the city ( Values ​​Citycode_pk, City_name, statecode_fk) ("881", "Bellary", "444")




insert into city values ​​(Citycode_pk, City_name, statecode_fk) ('118', 'Brisbane', '333') insert into city values ​​(Citycode_pk, City_name, statecode_fk) ('445', 'Tolga', '333')




paste into city values ​​(Citycode_pk, City_name, statecode_fk) ("770", "Wollongong", "233")

paste into city values ​​(Citycode_pk, City_name, statecode_fk) ("772", "Lahore", "788")

select * from the country select * from the state select * from the city

CHOOSE Country_Name
From the country;

SELECT state_name FROM state;

CHOOSE the name of the city from the city;

Plz slove and send me exams it urgently

0
Mar 27 '19 at 13:01
source share



All Articles