Answer: UNION ALL Set Operator
Find a detailed explanation of set operator UNION ALL.
Solution
The solution is given below:
Press + to interact
/* The query to use UNION ALL to combine result sets */SELECT e.EmpID, e.EmpName, s.SkillName, p.ProjectNameFROM Employees eLEFT JOIN Skills s ON e.EmpID = s.EmpIDLEFT JOIN Projects p ON e.EmpID = p.EmpID OR s.SkillID = p.SkillIDUNION ALLSELECT e.EmpID, e.EmpName, NULL AS SkillName, NULL AS ProjectNameFROM Employees eWHERE e.EmpID NOT IN (SELECT DISTINCT EmpID FROM Skills)AND e.EmpID NOT IN (SELECT DISTINCT EmpID FROM Projects)ORDER BY EmpName DESC;
Code explanation
The explanation of the solution code is given below:
Line 2: The first
SELECT
query selectsEmpID
,EmpName
,SkillName
, andProjectName
. The aliases used are forEmployees
,Skills
, andProjects
.Line 3: The data is retrieved from the
Employees
table. We use alias for the table.Line 4: The
LEFT JOIN
operation is applied withSkills
to combine the data based on theEmpID
column present in both theEmployees
andSkills
tables.Line 5: The
LEFT JOIN
operation is applied withProjects
to combine the data based on theEmpID
orSkillID
.Line 6: The
UNION ALL
keyword is used to combine the results of two queries, including duplicates.Line 7: The ...
Access this course and 1400+ top-rated courses and projects.