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
The image will help you to find the structure of db..$userId
is Uses id of user we wish to see the friend list for.
SELECT `connections`.*,`usr`.*,"'.$existImage.'" as main_image_url,"'.$existThumb.'" as thumb_image_url FROM `connections` `connections` JOIN `users` `usr` ON `usr`.`userId` = (CASE WHEN `connections`.`requestBy`="'.$userId.'" THEN connections.requestFor ELSE connections.requestBy END) WHERE `connections`.`requestBy` = "'.$userId.'" OR `connections`.`requestFor` = "'.$userId.'" AND `connections`.`requestStatus` = 1