Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q6 of 15
SQL - Common Table Expressions (CTEs)
Identify the error in this SQL query:
WITH first_cte AS (SELECT 100 AS amount), second_cte AS (SELECT amount FROM third_cte) SELECT * FROM second_cte;
Asecond_cte should not select from first_cte
Bfirst_cte is missing a SELECT statement
Csecond_cte references an undefined CTE named third_cte
DThe final SELECT statement should select from first_cte
Step-by-Step Solution
Solution:
  1. Step 1: Review CTE definitions

    first_cte and second_cte are defined; third_cte is not defined anywhere.
  2. Step 2: Check references

    second_cte tries to select from third_cte, which does not exist.
  3. Final Answer:

    second_cte references an undefined CTE named third_cte -> Option C
  4. Quick Check:

    All referenced CTEs must be defined [OK]
Quick Trick: All CTE references must be defined earlier [OK]
Common Mistakes:
  • Referencing CTEs not declared
  • Assuming CTEs can be referenced out of order
  • Confusing table names with CTE names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes