Bird
0
0

Identify the error in the following SQL query:

medium📝 Debug Q6 of 15
SQL - Common Table Expressions (CTEs)
Identify the error in the following SQL query:
WITH temp_cte (SELECT id, name FROM users) SELECT * FROM temp_cte;
ACTE name cannot be 'temp_cte'
BIncorrect use of SELECT inside the CTE
CMissing AS keyword before the subquery
DSELECT * FROM temp_cte is invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Review CTE syntax

    The correct syntax requires the AS keyword before the subquery in parentheses.
  2. Step 2: Analyze the query

    The query uses parentheses but omits AS, which causes a syntax error.
  3. Step 3: Evaluate options

    Missing AS keyword before the subquery correctly identifies the missing AS keyword. Options B, C, and D are incorrect because SELECT is valid inside CTE, the name is valid, and the final SELECT is correct.
  4. Final Answer:

    Missing AS keyword before the subquery -> Option C
  5. Quick Check:

    WITH cte_name AS (subquery) required [OK]
Quick Trick: Always use AS before CTE subquery [OK]
Common Mistakes:
  • Omitting AS keyword
  • Misplacing parentheses
  • Using invalid CTE names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes