Need to get all referrals ID with using MYSQL

Posted by Fero on Stack Overflow See other posts from Stack Overflow or by Fero
Published on 2011-01-16T11:03:45Z Indexed on 2011/01/16 13:53 UTC
Read the original article Hit count: 166

Filed under:

Hi all,

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...

© Stack Overflow or respective owner

Related posts about mysql