Bird
0
0

Find the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Common Table Expressions
Find the error in this query:
WITH cte1 AS (SELECT 10), cte2 AS (SELECT val FROM cte1) SELECT * FROM cte2;
Acte1 does not define column alias 'val'
BMissing comma between CTE definitions
CIncorrect use of SELECT * in final query
DCTEs cannot reference each other
Step-by-Step Solution
Solution:
  1. Step 1: Check cte1 definition

    cte1 selects 10 but does not assign a column name.
  2. Step 2: Check cte2 usage

    cte2 tries to select 'val' from cte1, but 'val' column does not exist.
  3. Final Answer:

    cte1 does not define column alias 'val' -> Option A
  4. Quick Check:

    Always alias columns in CTEs if referenced later [OK]
Quick Trick: Alias columns if referenced later [OK]
Common Mistakes:
  • Not aliasing columns in CTEs
  • Assuming default column names
  • Misunderstanding CTE references

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes