mysql8.0递归
sql举例:
WITH recursive c1 AS( select * from course_category where id = '1-1'union allselect t2.* from course_category t2 INNER JOIN c1 where t2.parentid=c1.id)
select * from c1 ORDER BY orderby;
解释:
WITH recursive c1 AS( //相当于创建了一个虚拟表
select * from course_category where id = '1-1' //虚拟表的第一条数据
union all
select t2.* from course_category t2 INNER JOIN c1 where t2.parentid=c1.id
//递归的语句,从这个表和虚拟表联表查询
)
select * from c1 ORDER BY orderby;//查出虚拟表中想要的数据