Bird
0
0

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:
  1. Step 1: Identify correct nested subquery syntax in FROM clause

    Nested subqueries in FROM require aliasing the subquery result.
  2. 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.
  3. Final Answer:

    Option A -> Option A
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes