title: MariaDB: Select the fields from one column in one table that are not in a subset of another column from another table
body: <p><strong>Update</strong>: Do not provide an answer that uses <code>NOT EXISTS</code>. According to <a href="http://www.techonthenet.com/mariadb/exists.php" rel="nofollow">MariaDB</a> "SQL statements that use the EXISTS condition in MariaDB are very inefficient since the sub-query is RE-RUN for EVERY row in the outer query's table." This query will be used <em><strong>a lot</strong></em>, so it needs to be efficient.</p>
  
  <p>I have two tables <code>following</code>:</p>
  
  <pre><code>CREATE TABLE `following` (
   `follower` int(1) unsigned NOT NULL,
   `followee` int(1) unsigned NOT NULL,
   PRIMARY KEY (`follower`,`followee`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>and <code>association_record</code>:</p>
  
  <pre><code>CREATE TABLE `association_record` (
   `user_id` int(1) unsigned NOT NULL,
   `post_id` int(1) unsigned NOT NULL,
   `answer_id` int(1) unsigned NOT NULL,
   `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (`user_id`,`post_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>What I want are the <code>follower</code>s of <code>followee</code> '5' who do not have an <code>association_record</code> with post '88'. The below SQL is what I came up with from reading other posts, but it doesn't get me the desired results:</p>
  
  <pre><code>select f.follower
  from following f
  left outer join association_record a
  on f.follower = a.user_id
  where f.followee = 5
  and a.post_id = 88
  and a.user_id is null
  </code></pre>