T-SQL “not in (select ” not working (as expected)
问题 I have an ordinary one-to-many relation: customer.id = order.customerid I want to find customers who have no associated orders. I tried: -- one record select * from customers where id = 123 -- no records select * from orders where customerid = 123 -- NO RECORDS select * from customers where id not in (select customerid from orders) -- many records, as expected. select * from customers where not exist (select customerid from orders where customers.customerid = customer.id) Am I mistaken, or