title: Filter MySQL Table Results based on List in Another Table
body: <p>I have a table that is giving me all of my table results data in the form of a json object array. This result returns the entire "messages" table data.</p>
  
  <p>The goal is for the logged in user <strong>$myusername</strong> to see all results except if a person appears in the 'blockRequests' table where <strong>$myusername</strong> is the <strong><em>reportedBy</em></strong>.</p>
  
  <p>My php:</p>
  
  <pre><code>$myusername = $_GET['username']; //the logged in user who is viewing the messages
  
  $rows = array();
  $stmt = $conn-&gt;query("SELECT * FROM messages ORDER BY datetime DESC");
  while($r = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {
      $rows[] = $r;
  }
  print json_encode(array('messageData' =&gt; $rows));
  </code></pre>
  
  <p>I have a seperate table <strong>'blockedRequests'</strong> that lists requests to block users, where a user reports the persons username as <strong>'blockedUsr'</strong>.</p>
  
  <p>I am simply trying to return ALL messages but exclude any <strong>'blockedUsr'</strong> that may appear in the blockedRequests table.</p>
  
  <p><a href="https://i.stack.imgur.com/TwAWa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TwAWa.jpg" alt="enter image description here"></a></p>
  
  <p>My SQL knowledge is so basic I can't figure out how to join the tables and get the desired results.</p>
  
  <p>What I tried</p>
  
  <pre><code>$stmt = $conn-&gt;query("SELECT messages.*, blockRequests.* FROM messages 
      LEFT JOIN blockRequests ON messageBox.user = blockRequests.reportedBy")
  </code></pre>
  
  <p>This returns the messages lists joined but not filtered. Any advice on how to join these tables to get the filtered messages would be great.</p>
  
  <p><strong>Edit (what I just tried)</strong></p>
  
  <pre><code>SELECT messages.*, blockRequests.* FROM messages
   LEFT JOIN blockRequests ON messages.user = 'suser'
  WHERE blockRequests.reportedBy IS NULL
  </code></pre>
  
  <p>This gives me the joined table but does not filter blockedUsrs, I still see them in the result set.</p>