title: SQL Select with multiple AND and OR's
body: <p>I'm sitting with a logic issues and I'm just confusing myself more and more.</p>
  
  <p>Example table</p>
  
  <h2>ID | CustID | Task  | Confirmed | Cancelled | Completed</h2>
  
  <p>1  |   20   | text  |    1      |     0     |     0<br>
  2  |   20   | text  |    1      |     1     |     0<br>
  3  |   20   | text  |    1      |     0     |     1<br>
  4  |   17   | text  |    0      |     1     |     0<br>
  5  |   17   | text  |    1      |     0     |     0<br>
  6  |   20   | text  |    1      |     NULL  |     NULL<br>
  7  |   20   | text  |    0      |     1     |     NULL     </p>
  
  <p>I wish to select all tasks for custID = 20 and are confirmed=1. If the task is cancelled=1 or completed=1, do not return the record.</p>
  
  <p>In this case, returned rows would be 1 and 6.</p>
  
  <p>My query thus far is</p>
  
  <pre><code>SELECT *
  FROM table1
  WHERE    
   (CustID = 20 AND Confirmed = 1 AND Cancelled &lt;&gt; 1 AND Completed &lt;&gt; 1) OR
   (CustID = 20 AND Confirmed = 1 AND Cancelled = 1 AND Completed &lt;&gt; 1) OR
   (CustID = 20 AND Confirmed = 1 AND Cancelled &lt;&gt; 1 AND Completed = 1)
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>