Bird
0
0

Identify the error in this correlated subquery:

medium📝 Debug Q6 of 15
SQL - Subqueries
Identify the error in this correlated subquery:
SELECT name FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees);
AThe subquery is not correlated but used as if it is
BMissing alias for the subquery
CIncorrect use of aggregate function AVG
DSyntax error due to missing WHERE clause in subquery
Step-by-Step Solution
Solution:
  1. Step 1: Check subquery correlation

    The subquery does not reference outer query columns, so it is not correlated.
  2. Step 2: Understand usage context

    The query uses the subquery as a simple scalar subquery, not correlated, so no error but no correlation.
  3. Final Answer:

    The subquery is not correlated but used as if it is -> Option A
  4. Quick Check:

    Subquery without outer reference = not correlated [OK]
Quick Trick: Correlation requires outer query column reference [OK]
Common Mistakes:
MISTAKES
  • Assuming all subqueries are correlated
  • Expecting error for missing WHERE
  • Confusing aggregate usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes