MySQL Recursive CTE
From http://www.mysqltutorial.org/mysql-recursive-cte Introduction to MySQL recursive CTE Notice that common table expression or CTE only available in MySQL version 8.0 or later. Therefore, you should have the right version of MySQL installed in order to use the statements in this tutorial. A recursive common table expression (CTE) is a CTE that has a subquery which refers to the CTE name itself. The following illustrates the syntax of a recursive CTE 1 2 3 4 5 6 WITH RECURSIVE cte_name AS ( initial_query -- anchor member UNION ALL recursive_query -- recursive member that references to the CTE name ) SELECT * FROM cte_name; A recursive CTE consists of three main parts: An initial query that forms the base result set of the CTE structure. The initial query part is referred to as an anchor member. A recursive query part is a query that references to the CTE name, therefore, it is called a recursive memb