MainMenu

Home Core Java Overview Maven Tutorials

Sunday, 15 January 2017

Query to join three table with example

Sample Query to join three table As like two table, three table can also be joined using INNER JOIN but they must have one column in common.
Syntax :

Select table1.Column_Name1,table1.Column_Name2
from Table1 as a
Inner Join Table2 as b
On a.column_name = b.column_name
Inner Join Table3 as c
On b.column_name = c.column_name


Consider the following tables : Salary:
Emp_idEmp_salaryEmp_name
0125000Chandan
0230000Adhiraj
0325000Akshat

Employee_record:
Emp_idEmp_cityEmp_name
201noidaSara
202gurgaonfatima

Employee_details:
Emp_idEmp_lastname
201Chauhan
202Singh

Query to join three tables :

select *
from salary as a
Inner Join Employee_record as b
On a.Emp_id = b.Emp_id
Inner Join Employee_details as c
on b.Emp_id = c.Emp_id


Result :
Emp_idEmp_salaryEmp_nameEmp_idEmp_cityEmp_nameEmp_idEmp_lastname
0125000Chandan201noidaSara201Chauhan
0230000Adhiraj202gurgaonfatima202Singh

Tag : How to Join three table?, SQL query to join three table with example

No comments:

Post a Comment