Let me explain as an example. Consider the following table:
Customer Id | Food ------------+--------- 1 | Pizza 1 | Burger 1 | Hot Dog 2 | Milkshake 2 | Burger 3 | Pizza
I want to delete all entries for customers who have NEVER ordered pizza. So, I have to be left this (customer number 2 removed):
Customer Id | Food ------------+--------- 1 | Pizza 1 | Burger 1 | Hot Dog 3 | Pizza
I know I can do NOT IN , but the performance is terrible.
What is the most efficient way to write this query to achieve this against 100,000 records in SQL Server?
sql-server tsql sql-server-2008
Mark robinson
source share