...

/

Answer: Subquery in the SELECT Clause

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,
ProjectName
FROM Projects AS p
WHERE p.EmpID IS NOT NULL;

Explanation

The explanation of the solution code is given below:

  • Lines 2–3: The SELECT query selects EmpName (coming from the subquery) and ProjectName from Projects, respectively. The e.EmpName refers to the EmpName column from the Employees table (aliased as e) and  p.EmpID refers to the EmpID column from the Projects table (aliased as p).  ...