← All topics
Quiz: Recursive CTEs: questions with answers
15 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. In a recursive CTE, how many times does the anchor query run?
- Q2. When does the recursion stop?
- Q3. What does this query return? (code)
- Q4. What does this query return? (code)
- Q5. To list everyone UNDER a manager, the recursive part joins on:
- Q6. Why can't a single self join list all of a CEO's indirect reports?
- Q7. Why is a calendar CTE LEFT JOINed to the sales table?
- Q8. The data has a loop: A manages B and B manages A. What is a safe fix in the query?
- Q9. What rule must the anchor and the recursive part follow?
- Q10. A filter WHERE level < 3 is written in the OUTER query instead of the recursive part. What happens?
- Q11. How many rows does this CTE produce: WITH RECURSIVE t(n) AS (SELECT 10 UNION ALL SELECT n - 3 FROM t WHERE n 1) SELECT FROM t?
- Q12. To walk UP from Arjun to the top manager, how does the recursive part join?
- Q13. A calendar CTE starts at '2026-01-01' and adds one day while d < '2026-01-31'. How many days does it produce?
- Q14. How does SQL Server write a recursive CTE?
- Q15. What is a downside of using UNION instead of UNION ALL inside a recursive CTE?