Skip to content
Advertisement

mysql join 2 tables filtering results

I have 2 tables users and referral.

here is the structure of 2 tables.

referral table

users table

i have 2 sections where a user can see received and sent referrals.

in received referral section how do i get the first_name and last_name from users table joining the from_user_id in referral table.

so far i came up with this query for received referral which gets me the intended result set. but how can get the users table firstname and lastname from referral table from_user_id

similarly in the sent referral section how do i get the user firstname and lastname joining users and referral table from_user_id key

any help would be greatly appreciated.

Advertisement

Answer

I think you want two joins on the users table:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement