Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - Common Table Expressions (CTEs)
What will be the output of this query?
SELECT * FROM (SELECT EmployeeID, Salary FROM Employees WHERE Salary > 50000) AS HighEarners WHERE EmployeeID < 100;
AAll employees with salary > 50000
BEmployees with salary > 50000 and EmployeeID < 100
CSyntax error due to missing alias
DEmployees with EmployeeID < 100 regardless of salary
Step-by-Step Solution
Solution:
  1. Step 1: Understand the subquery

    The subquery selects employees with salary greater than 50000 and aliases it as HighEarners.
  2. Step 2: Apply outer WHERE clause

    The outer query filters those results to employees with EmployeeID less than 100.
  3. Final Answer:

    Employees with salary > 50000 and EmployeeID < 100 -> Option B
  4. Quick Check:

    Subquery filters first, outer query filters second [OK]
Quick Trick: Subquery filters first, outer query filters next [OK]
Common Mistakes:
  • Forgetting alias after subquery
  • Assuming outer WHERE ignores subquery filter
  • Confusing syntax error with correct alias usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes