title: SQL Server: comparing two tables, two columns
body: <p>I have two tables. </p>
  
  <ul>
  <li><code>TableA</code> (<code>ID int, Match1 char, Match2 char, status char</code>)</li>
  <li><code>TableB</code> (<code>Match1 char, match2</code>)</li>
  </ul>
  
  <p>I want to flag rows in <code>tableA</code> as fail in status where for same <code>match1, match2</code> do not exist in <code>tableB</code>.</p>
  
  <p>Example:</p>
  
  <p><strong>TableA</strong></p>
  
  <pre><code>ID Match1 Match2 Status
  1   100    AB    
  2   100    AR
  3   200    BC
  4   200    VB
  5   200    AB
  </code></pre>
  
  <p><strong>TableB</strong></p>
  
  <pre><code>Match1 Match2
  100     AF
  100     AR
  100     BG
  200     AB
  200     BJ
  200     VB
  </code></pre>
  
  <p>Expected result:</p>
  
  <p><strong>TableA</strong></p>
  
  <pre><code>ID Match1 Match2 Status
  1   100    AB    FAIL 
  2   100    AR    NULL
  3   200    BC    FAIL
  4   200    VB    NULL
  5   200    AB    NULL
  </code></pre>
  
  <p>Thanks</p>
  
  <p>I used(not working):</p>
  
  <pre><code>Update A
  set status = 'FAIL'
  from TableA A
    Inner join TableB B
    ON A.match1 = B.match1
    WHERE A.match2 &lt;&gt; B.Match2
  </code></pre>