0

Table only has column

|id|Name|Parent

the parent being the root of the of the table

The result required

|Parent|child_id|Ancestral_Level

Child_ids All the succeeding Children where the parent

is their a way to do it on 5.6 as simple as possible?

Update

Now i just need the depth level to perent

DDD
  • 53
  • 2
  • 6
  • Possible duplicate of [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – Tim Biegeleisen Jan 05 '18 at 06:08
  • Please include your query and where you are getting stuck. – Tim Biegeleisen Jan 05 '18 at 06:08
  • `select IDAccount, Upline from (select * from TbBinary order by Upline, IDAccount) childaccounts, (select @pv := 'A') initialisation where find_in_set(Upline, @pv) > 0 and @pv := concat(@pv, ',', IDAccount)` – DDD Jan 05 '18 at 06:36
  • row 1 contains IDAccount A and Upline is A.. while row 2 IDAccount B and Upline is A – DDD Jan 05 '18 at 06:42
  • i've got it working `select IDAccount, name, Upline from (select * from BinaryTable order by Upline, IDAccount) Sorted_Table, (select @pv := '19') initialisation where find_in_set(Upline, @pv) > 0 and @pv := concat(@pv, ',', IDAccount) ` – DDD Jan 05 '18 at 07:38

1 Answers1

0

I think you may find the answer you are looking for here: Hierarchical data in MySQL: parents and children in one query

Tom Drake
  • 527
  • 5
  • 11