Skip to content

Instantly share code, notes, and snippets.

@hermanwhyd
Last active September 29, 2019 07:30
Show Gist options
  • Save hermanwhyd/5b96185171b4c350c443cf5cc73c106c to your computer and use it in GitHub Desktop.
Save hermanwhyd/5b96185171b4c350c443cf5cc73c106c to your computer and use it in GitHub Desktop.
MySQL Query Recursive Parent and child - Get All childs
-- mysql get all childs
select id,
name,
parent_id
from (select * from tablename
order by parent_id, id) tablename,
(select @pv := '100') initialisation
where find_in_set(parent_id, @pv) > 0
and @pv := concat(@pv, ',', id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment