Bird
0
0

Given the following SQL query, what will be the output?

medium📝 query result Q13 of 15
SQL - Common Table Expressions (CTEs)
Given the following SQL query, what will be the output?
WITH numbers AS (SELECT 1 AS num UNION ALL SELECT 2 UNION ALL SELECT 3) SELECT SUM(num) FROM numbers;
A1
B3
CSyntax error
D6
Step-by-Step Solution
Solution:
  1. Step 1: Understand the CTE content

    The CTE named 'numbers' contains rows with values 1, 2, and 3.
  2. Step 2: Calculate the SUM of num column

    Sum of 1 + 2 + 3 equals 6.
  3. Final Answer:

    6 -> Option D
  4. Quick Check:

    1 + 2 + 3 = 6 [OK]
Quick Trick: Sum values inside CTE to get result [OK]
Common Mistakes:
  • Assuming UNION ALL removes duplicates
  • Confusing SUM with COUNT
  • Expecting syntax error due to CTE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes