Find values from one SQL Server database table not present in another table

66 Views Asked by At

I have two tables with the following data (that I did not create nor can I control) that correlate on table1.workgroup = table2.id.

Table1

identity_id workgroup
58173 158938173
98156 670451782
41930 159381738

Table2

id name
158938173 Sales
670451782 Engineering
159381738 Support

I need to find where table1.workgroup does not have a correlating record in table2.

2

There are 2 best solutions below

0
Sergey On
SELECT workgroup
FROM TABLE_1 
  EXCEPT
SELECT id
FROM TABLE_2
1
lemon On

Yet another option:

SELECT Table1.workgroup
FROM      Table1
LEFT JOIN Table2 
       ON Table1.workgroup = Table2.id
WHERE Table2.id IS NULL