title: Logical operator NOT outside parentheses returning confusing results
body: <p>I have the following <code>WHERE</code> clause:</p>
  
  <p><code>NOT (division = 'Freemium' AND team = 999 AND touch IS NULL)</code></p>
  
  <p>I expected this to be the same as:</p>
  
  <p><code>no WHERE clause</code></p>
  
  <p>minus</p>
  
  <p><code>(division = 'Freemium' AND team = 999 AND touch IS NULL)</code></p>
  
  <p>but it is not. There are some differences when looking at the counts. Any insight?</p>
  
  <p>As an fyi, I am using HiveQL, but don't expect this to be any different for MySQL/SQL.</p>
  
  <hr>
  
  <p>added:</p>
  
  <p>Original Query:</p>
  
  <pre><code>CREATE TABLE AS example_so AS
  SELECT
    ticket_id,
    division,
    team,
    touch
  FROM sample_table
  WHERE
    day &gt;= '2016-01-01' AND
    current_state &lt;&gt; 'deleted'
  GROUP BY
    ticket_id,
    division,
    team,
    touch;
  </code></pre>
  
  <p>Query A:</p>
  
  <pre><code>SELECT
    COUNT(DISTINCT ticket_id)
  FROM example_so
  </code></pre>
  
  <p><strong>Result: 81,336</strong></p>
  
  <p>Query B:</p>
  
  <pre><code>SELECT
    COUNT(DISTINCT ticket_id)
  FROM example_so
  WHERE
    (team = 999 AND division = 'Freemium' AND touch IS NULL)
  </code></pre>
  
  <p><strong>Result: 355</strong></p>
  
  <p>Query C:</p>
  
  <pre><code>SELECT
    COUNT(DISTINCT ticket_id)
  FROM example_so
  WHERE
    NOT (team = 999 AND division = 'Freemium' AND touch IS NULL)
  </code></pre>
  
  <p><strong>Result: 80,682</strong></p>