How to use multiple CTEs in a single SQL query?
Use the key word WITH once at the top. If any of your Common Table Expressions (CTE) are recursive (rCTE) you have to add the keyword RECURSIVE at the top once also, even if not all CTEs are recursive: WITH RECURSIVE cte1 AS (…) — can still be non-recursive , cte2 AS (SELECT … UNION … Read more