I am building a multi-level referral system and I would like to offer bonuses on a pyramidal way. My simplified users table has this model:
id | referal
------------
1 | Null
----------
2 | 1
----------
3 | 2
----------
4 | 2
----------
5 | 4
----------
I was wondering how can I get an entire pyramid just from one mySQL query: Example : Get all refferals pyramid starting with user 5 Correct Answer: 5-4-2-1
I know to code this but Sql is faster!