1

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
deskFan
  • 31
  • 1
  • 4

2 Answers2

1
SELECT workgroup
FROM TABLE_1 
  EXCEPT
SELECT id
FROM TABLE_2
Sergey
  • 4,719
  • 1
  • 6
  • 11
1

Yet another option:

SELECT Table1.workgroup
FROM      Table1
LEFT JOIN Table2 
       ON Table1.workgroup = Table2.id
WHERE Table2.id IS NULL
lemon
  • 14,875
  • 6
  • 18
  • 38