title: MySql how to combine LEFT JOIN query with NOT IN query
body: <p>I need to combine <code>LEFT JOIN</code> query with <code>NOT IN</code> query and have to get the result values from these queries. I have get the correct results while using these two queries at separately.</p>
  
  <p>I have two tables likely <code>user</code> and <code>answer</code> </p>
  
  <p><code>user</code> table</p>
  
  <pre><code>user_id 
  1
  2
  3
  4
  5
  </code></pre>
  
  <p><code>answer</code> table </p>
  
  <pre><code>user_id     date 
  1           2015-10-15 21:23:14
  2           2015-10-15 20:23:14
  3           2015-11-11 16:23:14
  </code></pre>
  
  <p><code>LEFT JOIN</code> query:</p>
  
  <pre><code>SELECT user.user_id
  FROM user 
  LEFT JOIN answer 
    ON user.user_id = answer.user_id 
  WHERE DATEDIFF(NOW(),answer.date) &gt; 5
  </code></pre>
  
  <p>This query returns result <code>user_id</code> 1,2.</p>
  
  <p><code>NOT IN</code> query:</p>
  
  <pre><code>SELECT user.user_id 
  FROM user 
  WHERE user.user_id NOT IN (SELECT answer.user_id FROM answer)
  </code></pre>
  
  <p>This query returns result <code>user_ids</code> 4, 5.</p>
  
  <p>I need to combine this two queries into single query so I tried with these two below queries:</p>
  
  <pre><code> SELECT user.user_id 
   FROM user 
   LEFT JOIN answer 
     ON user.user_id = answer.user_id 
   WHERE (DATEDIFF(NOW(),answer.date) &gt; 5 
     AND user.user_id NOT IN (SELECT answer.user_id FROM answer))
  </code></pre>
  
  <p>and</p>
  
  <pre><code> SELECT user.user_id 
   FROM user 
   LEFT JOIN answer 
     ON user.user_id = answer.user_id 
   WHERE user.user_id NOT IN (SELECT answer.user_id FROM answer) 
     AND DATEDIFF(NOW(),answer.date) &gt; 5 
  </code></pre>
  
  <p>But these return empty <code>user_id</code>.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Expected result should contain values of <code>1,2,4,5</code></p>