As you can see below, I check if the current user is in columns user_aor friendsuser_b tables .
Depending on where the current user is located, I want to get his corresponding friend.
Somehow I can't get this syntax to work and wonder if anyone can tell me what happened (I get an error message on line 3 next to IF user_a = 2.
SELECT *
FROM friends
IF user_a = 2 THEN
JOIN user_profiles ON friends.user_b = user.profiles.user_id
WHERE user_a = 2
AND accepted = 1;
ELSEIF user_b = 2 THEN
JOIN user_profiles ON friends.user_a = user_profiles.user_id
WHERE user_b = 2
AND accepted = 1;
END IF;
source
share