Answer: Combining JOIN Statements
Find a detailed explanation of how to combine multiple joins on tables.
We'll cover the following...
We'll cover the following...
Solution
The solution is given below:
MySQL
/* The query to apply Mulitple JOINs */SELECT e.EmpName, p.ProjectName, s.SkillNameFROM Employees AS eINNER JOIN Projects AS p ON e.EmpID = p.EmpIDINNER JOIN Skills AS s ON p.SkillID = s.SkillID;
Explanation
The explanation of the code solution is given below:
Line 2: The
SELECTquery selectsEmpName,ProjectName, andSkillName. Thee.EmpNamerefers to theEmpNamecolumn from theEmployeestable (aliased ase), thep.ProjectNamerefers to theProjectNamecolumn from theProjectstable (aliased asp), and thes.SkillNamerefers to theSkillNamecolumn from theSkillstable (aliased ass).Line 3: The data is retrieved from the
Employeestable.Line 4: The
INNER JOINis applied to theProjectstable on theEmpIDcolumns in theEmployeesandProjectstables.Line 5: The
INNER JOINis applied withSkillsonSkillIDcolumns in theProjectsand ...