Bird
0
0

Find the issue in this query:

medium📝 Debug Q7 of 15
SQL - Subqueries
Find the issue in this query:
SELECT name FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department = d.department);
AMissing GROUP BY clause in subquery
BAVG function cannot be used in subqueries
CAlias 'd' is undefined in the outer query
DSubquery must return multiple rows
Step-by-Step Solution
Solution:
  1. Step 1: Check alias usage

    The subquery references d.department, but alias 'd' is not defined in the outer query.
  2. Step 2: Understand alias scope

    Only alias 'e' is defined; using 'd' causes an error.
  3. Final Answer:

    Alias 'd' is undefined in the outer query -> Option C
  4. Quick Check:

    Alias must be defined before use in correlated subquery [OK]
Quick Trick: Use only defined aliases in correlated subqueries [OK]
Common Mistakes:
MISTAKES
  • Using undefined aliases
  • Assuming AVG needs GROUP BY
  • Expecting subquery to return multiple rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes