title: SQL Server - How to check if a value does not exist in other rows of the same table for same column values?
body: <p>Following are the two tables in SQL Server: TABLE_A and TABLE_B</p>
  
  <p><a href="https://i.stack.imgur.com/VVePV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VVePV.png" alt="enter image description here"></a></p>
  
  <p>I need to get the output as follows:</p>
  
  <ul>
  <li><p>Get IDs from TABLE_A where Exist = 0</p>
  
  <p>We would get 100, 101 &amp; 102</p></li>
  <li><p>Now, among 100, 101 &amp; 102, no other rows (in the same table) with the same ID value should have Exist = 1</p>
  
  <p>Hence, 100 can't be selected as it has Exist = 1 in the 2nd row.</p>
  
  <p>So, only 101 &amp; 102 remain</p></li>
  <li><p>With the remaining ID values (101 &amp; 102), check against the ID column in TABLE_B where 'Exist' column value should not be equal to '1' in any of the rows</p>
  
  <p>In TABLE_B, 4th row has Exist = 1 for 102. So, that can't be selected</p>
  
  <p>We have only 101 now. This is required output and that should be selected.</p></li>
  </ul>
  
  <p>Could you let me know how to write the simplest query to achieve this please? Let me know if the question needs to be improved.</p>