title: postgres: filter out some results with join
body: <p>I’m trying to construct SQL query (I’m running postgres) which would filter out some posts:</p>
  
  <p>Lets say, that I’ve fot User model(id, name, and so on...), Blacklist model(with id, user_id, blacklisted_user_id) nad Post model(id, author_id, title, and so on).</p>
  
  <p>Imagine that user A(id=5) blocks user B(id=10).</p>
  
  <p>Neither user A nor B should see their posts.
  I’m trying with query which looks sth. like this:</p>
  
  <pre><code>SELECT posts.* FROM "posts" 
  LEFT JOIN blacklists b ON (b.user_id = posts.author_id OR 
                             b.blacklisted_user_id = posts.author_id)
  WHERE (b.user_id = 5 AND b.blacklisted_user_id = posts.author_id) OR
        (b.user_id = posts.author_id AND b.blacklisted_user_id = 5)
  </code></pre>
  
  <p>However, result is exactly opposite that I need: I’m getting only posts from blacklisted user.</p>
  
  <p>When I use <code>b.user_id != 5</code>, I’m getting empty response.</p>