Tag Archives: sql server

Using Not Exists in SQL

Suppose I have a query where I want everything in table A that is not in table B. For example, I want all the customers in table A who have not placed an order in table B. There are a surprising number of ways to build a select statement that returns the correct answer. Some of those queries may also give you an incorrect answer if one of the target fields has nullable data.

Aaron Bertrand’s article will walk you through each of the examples to show you why Not Exists is the best option for this type of query.