Search⌘ K
AI Features

Answer: Combining JOIN Statements

Explore how to write SQL queries combining multiple JOIN statements to retrieve related data across tables. Understand using INNER JOIN, LEFT JOIN, and RIGHT JOIN with aliases and selective columns. This lesson helps you master combining join conditions and alternative solutions to cover various querying scenarios.

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 ...