Reputation: 1
I have two tables for inventory tracking. TABLE_A is for the actual records, TABLE_B is for that record's history with regards to it's location; moved from Building 1 to Building 2, etc.
Most of the records in TABLE_A are in TABLE_B, but there are a few that are in TABLE_A that are not in TABLE_B. I'm trying to write a query to only get which records in TABLE_A do not exist in TABLE_B.
TABLE_A.Item_ID
101
102
103
104
105
TABLE_B.Item_ID
101
103
104
I thought doing the following would work, but it's not.
select a.Item_ID
from TABLE_A a
left outer join TABLE_B b on (a.Item_ID = b.Item_ID)
where b.Item_ID is null
order by a.Item_ID desc
Thanks in advance for your help.
Upvotes: 0
Views: 35
Reputation: 142705
I'd try the MINUS
set operator:
select item_id from table_a
minus
select item_id from table_b
Upvotes: 1