I have a SQL query that left joins a table in different ways depending on a condition.
SELECT m.id, u.first_name AS otherUser
FROM matches AS m
IF (u.id=m.user2I
You can not use the IF THEN ELSE END IF-stuff in a SELECT in this way. However, you can use it in stored procedures and functions.
I would JOIN u.id with both m.user1ID and m.user2ID and use DISTINCT to avoid duplicates.
There is a IF() which you can use in SELECTs, but you can not do flow control with IF().