I have two tables, one called "users" other called "referral". Every user has a code associated with it and this is how they look:
USERS TABLE
user_id name ref_type other_referral
1 Ely friend SA0987
2 Sandra page
3 Karla friend EC0000
4 Tania email
REFERRAL TABLE
user_id code
1 EC0000
2 SA0987
I want to select everything from the users table, but if the referral matches with friend and other_referral is not empty, then I need instead of that alpha numerical code, I want the name of the user, which can be associated from the table REFERRAL.
EXAMPLE:
id name ref_type other_referral
1 Ely friend Sandra
2 Sandra page
3 Karla friend Ely
4 Tania email