0

i have MYSQL Skillz, BUT this is a lil bit to heavy for me...

I have this DB Structure:

enter image description here

and I want to get alle childs, grandChilds, grandGrandChilds etc etc of a given parent.

example:

when I select the parent 189 as starting point i want to get this result of Ids here:

id {234, 235, 238, 239, 240, 245, 246, 2037, 2038}

and my approach was this here:

SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM (
SELECT @pv:=(SELECT GROUP_CONCAT(id SEPARATOR ',') FROM companies
WHERE parent IN (@pv)) AS lv FROM companies
JOIN
(SELECT @pv:=189)tmp
WHERE id IN (@pv)) a;

But then i only get this result here: IDs:{234,235,246,238,240}

So some of them are missing....

Is there any other possibility to get really all childs of a given parent node?

Thank you so much for any hints...

EDIT: ok i have read that this is not possible in mysql (less then mysql 8.0) so we are using a lower version atm)

but i am scripting in PHP, maybe I can find a solution programatically instead of building a huge sql query....

WEBGONDEL UG
  • 147
  • 1
  • 2
  • 12
  • Possible duplicate of [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – P.Salmon Feb 05 '18 at 10:47
  • I have marked this as a duplicate because the linked solution provides the result you ask for (with some obvious tweaks) – P.Salmon Feb 05 '18 at 10:49

0 Answers0