title: SQL WHERE excluding records using AND and NOT
body: <p>Here's a query I'm working on:</p>
  
  <pre><code>SELECT  TBL_SUB_KEY AS port
        , poe.[TBL_COMPANY]
        , poe.[TBL_DIVISION_1]
  FROM    dbo.TMVKTAB AS poe
  WHERE   ( TBL_NUMBER = '8A' )
          AND ( TBL_SUB_KEY &lt;&gt; '' )
          AND ( poe.[TBL_COMPANY] &lt;&gt; '011'
                AND poe.[TBL_DIVISION_1] &lt;&gt; '11'
              )
  </code></pre>
  
  <p>What I want returned are all the records that are <strong>not</strong> in Company = '011'/Division_1' = '11'.</p>
  
  <p>I thought combining the company/division in the () would achieve this, but it does not. It eliminates all the company '011' records and it eliminates all division '11' records.</p>
  
  <p>However, when I do this:</p>
  
  <pre><code>SELECT  TBL_SUB_KEY AS port
        , poe.[TBL_COMPANY]
        , poe.[TBL_DIVISION_1]
  FROM    dbo.TMVKTAB AS poe
  WHERE   ( TBL_NUMBER = '8A' )
          AND ( TBL_SUB_KEY &lt;&gt; '' )
          AND NOT ( poe.[TBL_COMPANY] = '011'
                AND poe.[TBL_DIVISION_1] = '11'
              )
  </code></pre>
  
  <p>it seems to pull the correct results. Why is this?</p>