Bird
0
0

Identify the syntax error in the following SQL using a CTE:

medium📝 Debug Q6 of 15
SQL - Common Table Expressions (CTEs)
Identify the syntax error in the following SQL using a CTE:
WITH EmployeeCTE (id, name) AS SELECT id, name FROM employees GROUP BY id SELECT * FROM EmployeeCTE;
ASELECT * cannot be used after a CTE
BIncorrect use of GROUP BY without aggregation
CCTE name cannot have column aliases
DMissing parentheses around the SELECT statement in the CTE definition
Step-by-Step Solution
Solution:
  1. Step 1: Review CTE syntax

    A CTE must have its SELECT statement enclosed in parentheses after the AS keyword.
  2. Step 2: Identify the error

    The query lacks parentheses around the SELECT statement in the CTE definition.
  3. Final Answer:

    Missing parentheses around the SELECT statement in the CTE definition -> Option D
  4. Quick Check:

    Check for parentheses after AS [OK]
Quick Trick: CTE SELECT must be enclosed in parentheses [OK]
Common Mistakes:
  • Omitting parentheses around the CTE query
  • Misusing GROUP BY without aggregation
  • Assuming column aliases are not allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes