Search⌘ K
AI Features

Answer: Combining JOIN Statements

Explore how to combine multiple JOIN statements to retrieve data from several SQL tables. Understand the use of INNER JOIN, LEFT JOIN, and RIGHT JOIN, along with table aliases and selective column retrieval, to master data combination in SQL queries.

Solution

The solution is given below:

MySQL
/* The query to apply Mulitple JOINs */
SELECT e.EmpName, p.ProjectName, s.SkillName
FROM Employees AS e
INNER JOIN Projects AS p ON e.EmpID = p.EmpID
INNER JOIN Skills AS s ON p.SkillID = s.SkillID;

Explanation

The explanation of the code solution is given below:

  • Line 2: The SELECT query selects EmpName, ProjectName, and SkillName. The e.EmpName refers to the EmpName column from the Employees table (aliased as e), the p.ProjectName refers to the ProjectName column from the Projects table (aliased as p), and the s.SkillName refers to the SkillName column from the Skills table (aliased as s).

  • Line 3: The data is retrieved from the Employees table.

  • Line 4: The INNER JOIN is applied to the Projects ...