Bird
0
0

Identify the error in this SQL query using CTEs:

medium📝 Debug Q14 of 15
SQL - Common Table Expressions (CTEs)
Identify the error in this SQL query using CTEs:
WITH cte1 AS (
  SELECT id, name FROM users
),
cte2 AS (
  SELECT id, name FROM cte3 WHERE id > 5
)
SELECT * FROM cte2;
ASELECT statement missing after CTEs
BMissing comma between CTE definitions
Ccte2 references cte3 which is not defined
DCTEs cannot reference other CTEs
Step-by-Step Solution
Solution:
  1. Step 1: Check CTE definitions

    cte1 is defined, but cte2 references cte3 which is not defined anywhere.
  2. Step 2: Confirm syntax correctness

    Comma between cte1 and cte2 is present, and SELECT after CTEs is correct, so no syntax error there.
  3. Final Answer:

    cte2 references cte3 which is not defined -> Option C
  4. Quick Check:

    Undefined CTE reference = A [OK]
Quick Trick: Check all referenced CTE names are defined above [OK]
Common Mistakes:
  • Assuming missing comma error
  • Thinking CTEs can't reference others
  • Overlooking undefined CTE names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes