1.

Write an SQL query to join three tables.

Answer»

At times, you might need to retrieve data from three or more tables at once. A multi-table join requires consecutive JOIN operations: the first and second tables are joined to form a virtual table and then the third table is joined to this virtual table. Let's take a look at three tables. 

Here’s the Employee table.

Emp_IDEmp_NameEmp_No
101Ashish Kaktan9450425345
102Raj Choudhary8462309621
103Vivek Oberoi7512309034
104Shantanu Khandelwal9020330023
105Khanak Desai8451004522

Here's the Employment table. 

Emp_IDEmp_ProfileEmp_Email
101Content Writerashish@scaler.com
104Data Analystshantanu@scaler.com
105Software Engineerkhanak@scaler.com
109Development Executiveakshay@scaler.com
108Marketing Managernikita@scaler.com

Here’s the EmpDetail.

Emp_CountryEmp_EmailEmp_JoinDate
Germanyashish@scaler.com2021-04-20
Indiashantanu@scaler.com2022-12-11
Indiakhanak@scaler.com2022-01-03
Europeakshay@scaler.com2023-02-15
Mexiconikita@scaler.com2020-05-23
SELECT Emp_Name, Emp_No, Emp_Profile, Emp_Country, EmpJoinDate,
FROM Employee e INNER JOIN Employment m ON
e.Emp_ID = m.EMP_ID INNER JOIN EmpDetail d on
d.Emp_Email = m.Emp_Email;

Output:

Emp_NameEmp_NoEmp_ProfileEmp_CountryEmp_JoinDate
1019450425345Content WriterGermany2021-04-20
1049020330023Data AnalystIndia2022-12-11
1058451004522Software EngineerIndia2022-01-03



Discussion

No Comment Found