0

I have a table like this:

id user_id referral_id
1 1 null
2 2 1
3 3 2
4 4 1
5 5 3

When I query where user_id = 5, I would like to get the following:

id user_id referral_id
1 1 null
2 2 1
3 3 2
5 5 3

I'm using MySQL 5 so I can't use cte. Edit: I need the parents for the id not the children.

camila
  • 1
  • 1
  • No this works for going down not up the list – camila Sep 27 '21 at 19:06
  • 1
    @stu That question's answer is flawed for truely generic path traversal. This example shows that it breaks when children have lower `id`s that their parents : http://sqlfiddle.com/#!9/09ea61 – MatBailie Sep 27 '21 at 19:07
  • @MatBailie there are 16 answers, which are you referring to? – Stu Sep 27 '21 at 19:10

0 Answers0