Which of the following shows the correct way to use a nested subquery in the FROM clause?
easy📝 Syntax Q3 of 15
SQL - Subqueries
Which of the following shows the correct way to use a nested subquery in the FROM clause?
ASELECT emp_id FROM (SELECT emp_id FROM Employees WHERE dept_id = 10) AS DeptEmployees;
BSELECT emp_id FROM Employees WHERE dept_id = SELECT dept_id FROM Departments WHERE name = 'HR';
CSELECT emp_id FROM Employees WHERE dept_id IN SELECT dept_id FROM Departments;
DSELECT emp_id FROM Employees WHERE dept_id = (SELECT dept_id FROM Departments WHERE name = 'HR'
Step-by-Step Solution
Solution:
Step 1: Identify correct nested subquery syntax in FROM clause
Nested subqueries in FROM require aliasing the subquery result.
Step 2: Analyze options
SELECT emp_id FROM (SELECT emp_id FROM Employees WHERE dept_id = 10) AS DeptEmployees; correctly uses parentheses and alias 'AS DeptEmployees'. Others have syntax errors or missing parentheses.
Final Answer:
Option A -> Option A
Quick Check:
Subquery in FROM must be aliased [OK]
Quick Trick:Always alias subqueries in FROM clause [OK]
Common Mistakes:
MISTAKES
Missing alias for subquery in FROM clause
Omitting parentheses around subquery
Using subquery without proper syntax
Master "Subqueries" in SQL
9 interactive learning modes - each teaches the same concept differently