Answer: Subquery in the SELECT Clause
Find a detailed explanation of using subqueries on multiple tables.
Solution
The solution is given below:
Press + to interact
/* The use of subquery to find the employees working on a project */SELECT (SELECT e.EmpName FROM Employees AS e WHERE e.EmpID = p.EmpID) AS EmpName,ProjectNameFROM Projects AS pWHERE p.EmpID IS NOT NULL;
Explanation
The explanation of the solution code is given below:
Lines 2–3: The
SELECT
query selectsEmpName
(coming from the subquery) andProjectName
fromProjects
, respectively. Thee.EmpName
refers to theEmpName
column from theEmployees
table (aliased ase
) andp.EmpID
refers to theEmpID
column from theProjects
table (aliased asp
). ...