I have 2 tables, orderData and stagingOrderData. I need to see if there are any rows in the stagingOrderData which exists in the orderData so I can delete them from the stagingOrderData table before I import.
Test cases - I tried a join
select * from
dbo.stagingOrderData s
inner join dbo.OrderData o
on s.productid = o.productid
and s.barcode = o.barcode
and s.orderid = o.orderid
and then and "exists"
select * from
dbo.stagingOrderData s
where exists(dbo.OrderData o
select * from
where o.productid = s.productid
and o.barcode = s.barcode
and o.orderid = s.orderid )
The statement with the "exists" seems to be much faster.