Bird
0
0

Given the following query, what will be the output?

medium📝 query result Q13 of 15
PostgreSQL - Common Table Expressions
Given the following query, what will be the output?
WITH cte1 AS (SELECT 1 AS num), cte2 AS (SELECT num * 2 AS double_num FROM cte1) SELECT * FROM cte2;
A[{num: 2}]
B[{num: 1, double_num: 2}]
C[{double_num: 2}]
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cte1

    cte1 returns one row with column num = 1.
  2. Step 2: Analyze cte2 using cte1

    cte2 selects num * 2 as double_num, so double_num = 1 * 2 = 2.
  3. Step 3: Final SELECT from cte2

    Only double_num column is selected, so output is [{double_num: 2}].
  4. Final Answer:

    [{double_num: 2}] -> Option C
  5. Quick Check:

    cte2 output columns = double_num [OK]
Quick Trick: Check which columns each CTE outputs carefully [OK]
Common Mistakes:
  • Assuming cte2 includes all columns from cte1
  • Expecting num column in final output
  • Thinking query has syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes