I have a table user and in addition INNER JOIN it with table cities and a few others already. Now I also have the following table:
blocked_user
--------------------------------------------------------
id | user1_id | user2_id | timestamp
How can I use LEFT JOIN WHERE IS NULL, so both user combinations (user1 blocked user2 or user2 blocked user1) are excluded from the search results?
user
--------------------------------------------------------
id | username | ...
Thank you very much in advance for you help!
I’m guessing that you have a current user (the user who is performing the request) and you want to hide all users they have blocked or all users who have blocked them. I’m also assuming that
user1_idis the user who did the blocking, anduser2_idis the user they blocked. You should edit your question to make those points more clear.If that’s right, here’s what I would do:
I think it makes sense to use two separate
LEFT JOIN ... WHERE ... IS NULLconstructs because you are really checking for two different situations.