Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table person( id int auto_increment, name varchar(100), manager_id int, primary key (id) ); insert into person (name, manager_id) values('Vasya', null), ('Petya', 1), ('Kostya', 2), ('Serega', 3), ('Sanya', null); with recursive person_tree(id, name, manager_path) as( select id, name, cast(id as char(200)) from person where manager_id is null union all select s.id, s.name, concat(m.manager_path, ",", s.id) from person_tree m join person s on m.id=s.manager_id ) select * from person_tree order by manager_path;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear