title: How should I design a user blocking system?
body: <p>I've created little social website which has user generated content in it. And users should have option to block each other if they don't like what they post.</p>
  <p>So I'm using postgresql and I have three simple tables.</p>
  <pre><code>Table User
  id (pk)  | user_name
  1       | a
  2       | b
  3       | c
  
  Table Post
  id (pk)  | user_id (fk)
  1       | 1
  2       | 3
  3       | 2
  4       | 2
  
  Table Block
  id (pk) | blocker_id (fk)  | blocked_id (fk)
  1       | 1              | 2
  2       | 2              | 1
  </code></pre>
  <p>Btw, as you can see, I use two-way block because I don't want that if user1 blocks user2, user2 shouldn't see user1's posts too.</p>
  <p>I wrote an sql:</p>
  <pre><code>SELECT * FROM Post p INNER JOIN Block b
  ON p.user_id = b.blocker_id
  WHERE b.blocked_id &lt;&gt; @current_user_id
  </code></pre>
  <p>But what if user hasn't blocked anyone? This sql doesn't cover that case and it only shows user's posts that has record on the <strong>block</strong> table.</p>
  <h3>What I expect:</h3>
  <ul>
  <li>For user1, this sql should return user3's and user1's posts.</li>
  <li>For user2, it should return user3's and user2's posts.</li>
  <li>For user3, it should return <strong>every users</strong> posts.</li>
  </ul>
  <p>How can I do that?</p>
  <p>Thanks.</p>