Last active
September 29, 2019 07:30
-
-
Save hermanwhyd/5b96185171b4c350c443cf5cc73c106c to your computer and use it in GitHub Desktop.
MySQL Query Recursive Parent and child - Get All childs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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