title: SQL Server - select records from one table which are not in a subset of another table
body: <p>I am trying to prepare a query to insert new entries in a daily report into a separate table in a SQL Server database.</p>
  <p>I have two tables as follows:</p>
  <p><strong>Table 1</strong></p>
  <pre><code>id   style_code   location_code
  -------------------------------
   1   abcd         IST
   2   abcd         DEL
   3   wxyz         DEL
  </code></pre>
  <p><strong>Table 2</strong></p>
  <pre><code>id    style_code   location_code
  --------------------------------
   1    abcd         IST
   2    wxyz         IST
   3    abcd         DEL
   4    wxyz         DEL
  </code></pre>
  <p>I want to select all the rows in Table 2 where the combination of 'style_code' and 'location_id' DO NOT exist in Table 1. In this particular example, that would mean returning row 2 from Table 2 as 'wxyx &amp; IST' do not exist in Table 1. (There is no relationship between the id columns. Table 2 is a temporary table)</p>
  <p>I have been trying to put a join into a Select query with NOT IN, but I cannot seem to get the query to work correctly.</p>
  <pre><code>SELECT *
  FROM [Table 2]
  WHERE style_code NOT IN (SELECT style_code
                           FROM [Table 1] 
                           INNER JOIN [Table 2] ON [Table 2].location_code = [Table 1].location_code);
  </code></pre>
  <p>I have a beginners understanding of SQL coding, but am no expert, and would appreciate any guidance.</p>