So, I have this MySQL problem.
I’ve been looking at LEFT JOIN, INNER JOIN etc. And as I understand LEFT JOIN joins from left and if the right part doesn’t exist it’s values get set to NULL. And with INNER JOIN if there is no match for the join, an empty set is returned.
As you can see from my previous statement I join different statistics and such for one of the users in the match. But if uid2 isnt friend with uid1 this will give null in my case for all fields in friends.*
How would I do to get all the friends fields if they are friends and no fields from friends if they arent. (I dont want to do a separate statement before to check if they’re friends).
This is my previous statemenet:
SELECT matches.*, statistics.*, friends.*, users.username
FROM `matches`
LEFT JOIN statistics ON matches.uid1=statistics.uid
LEFT JOIN users ON matches.uid1=users.uid
LEFT JOIN friends ON matches.uid1=friends.fid AND matches.uid2=friends.uid
WHERE matches.mid IN (269,231,131)
Then you just replace the last
LEFT JOINwith anINNER JOIN:However, it’s not possible to selectively not return the columns from the
friendstable when they can’t be joined.