Bird
0
0

Which of the following is the correct syntax to combine the anchor and recursive parts in a recursive CTE?

easy📝 Syntax Q3 of 15
PostgreSQL - Common Table Expressions
Which of the following is the correct syntax to combine the anchor and recursive parts in a recursive CTE?
ASELECT * FROM cte_name WHERE condition UNION SELECT * FROM cte_name WHERE condition
BSELECT * FROM cte_name WHERE condition UNION ALL SELECT * FROM cte_name WHERE condition
CSELECT * FROM cte_name WHERE condition INTERSECT SELECT * FROM cte_name WHERE condition
DSELECT * FROM cte_name WHERE condition EXCEPT SELECT * FROM cte_name WHERE condition
Step-by-Step Solution
Solution:
  1. Step 1: Recall recursive CTE syntax

    The anchor and recursive parts are combined using UNION ALL to include all rows, including duplicates if any.
  2. Step 2: Identify correct set operator

    UNION removes duplicates, but recursive CTEs require UNION ALL to avoid losing rows during recursion.
  3. Final Answer:

    SELECT * FROM cte_name WHERE condition UNION ALL SELECT * FROM cte_name WHERE condition -> Option B
  4. Quick Check:

    Recursive CTE uses UNION ALL [OK]
Quick Trick: Use UNION ALL to combine anchor and recursive parts [OK]
Common Mistakes:
  • Using UNION instead of UNION ALL
  • Using INTERSECT or EXCEPT incorrectly
  • Omitting UNION ALL clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes