Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need the examples query for innerjoin between the 3 or 4 tables.
Posted

Joining tables is not a big deal. Try the given example below:
Example : Suppose you are having 4 tables(Table1, Table2, Table3, Table4).
SQL
--Table1
ID        EmployeeID
---------------------
1         S001
2         S002

--Table2
ID        Name
------------------
1         Amit
2         Amy

--Table3
ID        Address
------------------
1         Bangalore
2         Gaya

--Table4
ID        PhoneNo
------------------
1         0123456789
2         9876543210


Now, if you want to join these three tables for data of corresponding ID, you can try this sql:
SQL
SELECT A.EmployeeID, B.Name, C.Address, D.PhoneNo
    FROM Table1 A INNER JOIN Table2 B on A.ID = B.ID
    INNER JOIN Table3 C on A.ID = C.ID
    INNER JOIN Table4 D on A.ID = D.ID
    WHERE A.ID = 101 -- You can add any conditions

Refer the links below for more details:
MSDN : Joining Three or More Tables[^]
SQL Server 2008 - How to Join 3 tables[^]


--Amit
 
Share this answer
 
Example:...
SQL
SELECT
employee.EmployeeId,
employee.Employeename,
enduser.username,
exedistributornw.HeadQuaters,
party.PartyName
FROM
employee
Inner Join enduser ON employee.EmployeeId = enduser.employeeid
Inner Join exedistributornw ON employee.EmployeeId = exedistributornw.EmployeeId
Inner Join party ON exedistributornw.PartyId = party.PartyId
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900