title: Mysql query NOT EXISTS doesn't work properly
body: <p>I have the following two tables and columns</p>
  
  <p>Table 1: transactionid</p>
  
  <p>Table 2: transactionid and status</p>
  
  <p>I need to get results from the table 1 if the same transactionid doesn't exist in table2</p>
  
  <p>If the same transactionid in table2 exists but the status is different than 2 then it shouldn't return the table1 row</p>
  
  <p>If the same transactionid in table2 exists and the status is 2 then it should return the table 1 row but i need to know this so i can show an error inside my website</p>
  
  <p>I currently have:</p>
  
  <pre><code>select * from table1 where not exists (select null from table2
              WHERE table1.transactionid = table2.transactionid AND status &lt;&gt; 2)
  </code></pre>
  
  <p>i would need something like this (it doesn't work properly)</p>
  
  <pre><code>select *, (select count(*) from table2 where table1.transactionid = table2.transactionid AND status = 2) as orderswitherrors from table1 where not exists (select null from table2
              WHERE table1.transactionid = table2.transactionid AND status &lt;&gt; 2)
  </code></pre>
  
  <p>So in php i can check if that transactionid has an error in table2 with if ($row->orderswitherrors > 0) ...</p>
  
  <p>Thank you</p>