Answer: Subquery in the SELECT Clause
Understand how to use subqueries within the SELECT clause to fetch related data from different tables. Learn to apply aliases, filtering with WHERE clauses, and explore alternative solutions involving LEFT, RIGHT, and INNER JOINS to write efficient SQL queries.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Lines 2–3: The
SELECTquery selectsEmpName(coming from the subquery) andProjectNamefromProjects, respectively. Thee.EmpNamerefers to theEmpNamecolumn from theEmployeestable (aliased ase) andp.EmpIDrefers to theEmpIDcolumn from theProjectstable (aliased asp).Line 4: The data is retrieved from the
Projectstable.Line 5: The
WHEREclause ensures that only those ...