MySql | Update upline for tree like structure
I have a table like
ID | ParentID | Upline | Name | Address
----------------------------------------
1 | Null | | Xyz | Home
2 | 1 | | ABC | Home
3 | 2 | | DEF | Home
4 | 3 | | GHI | Home
5 | 3 | | GHI | Home
I need to fill the upline with a query. For example upline for 4 will be
3,2,1 and upline for 3 will be 2,1
So the table after query should look like
ID | ParentID | Upline | Name | Address
----------------------------------------
1 | Null | Null | Xyz | Home
2 | 1 | 1 | ABC | Home
3 | 2 | 2,1 | DEF | Home
4 | 3 | 3,2,1 | GHI | Home
5 | 3 | 3,2,1 | GHI | Home
How can I do the trick with a MySQL query?
Thanks
No comments:
Post a Comment