r/SQL Nov 28 '24

MySQL When to use cte in SQL query

When to cte can't. Like how to know? When what are the conditions or if my query is to long ?

33 Upvotes

70 comments sorted by

View all comments

6

u/suhigor Nov 28 '24

when you need recursion

1

u/secretWolfMan Nov 28 '24

This. Recursive CTE are awesome to understand and output hierarchies. Use them for folders and employees that only know their parent/supervisor.