I having a referral table like below.
> id referredByID referrerID
>
> 1001 1 2
>
> 1002 2 3
>
> 1003 2 4
>
> 1004 5 7
From the above table structure i need to get the users whom i referred and the users whom are referred by their referrals.
For Example:
-
I am referredByID-1
-
I referred the ID – 2
-
Now the ID – 2 referred ID -3
-
And in the same case ID-2 referred ID – 4
Now my output needs to be look like:
Referrals Done By Me:
id – 2
id – 3
id – 4
How can this be done using MYSQL.
Any help will be appreciated.. Thanks in advance…
I think I got everything the right way round but your naming conventions confused me so you’d better check everything.
If I call the following stored procedure:
I get the following results:
full script here: http://pastie.org/1466596
Stored procedure
Hope this helps 🙂