0

I have this table the contains user_id and father_id. I want to select all the father_ids that are associated with the user_id until the value of the father_id = 0 and store them in a comma-separated format.

Table: network

select user_id, father_id from network where user_id = 1762;


user_id father_id
1762    1761


select user_id, father_id from network where user_id = 1761; -- resulting father_id from the first query


user_id father_id
1761    1760


select user_id, father_id from network where user_id = 1760; -- resulting father_id from the second query


user_id father_id
1760    0

In this example, I want to get all the father_ids until i reached father_id = 0 by using the resulting father_id as the next user_id.

sticky bit
  • 36,626
  • 12
  • 31
  • 42
Morgi
  • 1
  • 1

0 Answers0