Bird
0
0

You want to list all managers and their subordinates up to 3 levels deep using a recursive CTE. Which modification ensures the recursion stops at level 3?

hard📝 Application Q8 of 15
SQL - Common Table Expressions (CTEs)
You want to list all managers and their subordinates up to 3 levels deep using a recursive CTE. Which modification ensures the recursion stops at level 3?
AUse LIMIT 3 in the final SELECT statement
BUse WHERE clause in anchor member to limit to 3 rows
CAdd a HAVING clause to filter levels after recursion
DAdd a level column starting at 1 and increment in recursive member, stop when level <= 3
Step-by-Step Solution
Solution:
  1. Step 1: Track recursion depth

    Add a level column starting at 1 in anchor and increment in recursive member.
  2. Step 2: Stop recursion at level 3

    Include WHERE level <= 3 in recursive member to limit depth.
  3. Final Answer:

    Add a level column starting at 1 and increment in recursive member, stop when level <= 3 -> Option D
  4. Quick Check:

    Control recursion depth with level counter [OK]
Quick Trick: Use a level counter column to limit recursion depth [OK]
Common Mistakes:
  • Trying to limit rows in anchor member
  • Using LIMIT instead of recursion control
  • Filtering after recursion instead of during

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes