Bird
0
0

Which of the following is the correct basic syntax to start a recursive CTE in SQL?

easy📝 Syntax Q12 of 15
SQL - Common Table Expressions (CTEs)
Which of the following is the correct basic syntax to start a recursive CTE in SQL?
AWITH cte_name AS (SELECT ... UNION ALL SELECT ... FROM cte_name ...)
BCREATE RECURSIVE cte_name AS SELECT ...
CSELECT * FROM cte_name RECURSIVE
DWITH RECURSIVE cte_name SELECT ... UNION SELECT ...
Step-by-Step Solution
Solution:
  1. Step 1: Recall recursive CTE syntax

    The standard syntax starts with WITH cte_name AS (anchor_query UNION ALL recursive_query).
  2. Step 2: Check options for correct form

    WITH cte_name AS (SELECT ... UNION ALL SELECT ... FROM cte_name ...) correctly shows the anchor and recursive parts combined with UNION ALL and references the CTE name in the recursive part.
  3. Final Answer:

    WITH cte_name AS (SELECT ... UNION ALL SELECT ... FROM cte_name ...) -> Option A
  4. Quick Check:

    Recursive CTE syntax = WITH + UNION ALL + self-reference [OK]
Quick Trick: Recursive CTE uses WITH + UNION ALL + self-reference [OK]
Common Mistakes:
  • Using CREATE instead of WITH
  • Omitting UNION ALL
  • Not referencing the CTE name recursively

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes