inding data in a relational database is usually a simple task, especially if you’re simply comparing entries to a specific value, but queries rapidly become more complicated when you start hunting for data that’s missing, in other words, data that could exist, but doesn’t. Missing data is data related to existing data that simply doesn’t occur. You could find missing values using a two-query solution, but SQL’s EXISTS predicate can help you quickly find missing values with just one query?a subquery to be exact.
For example, you may create a query to find active customers by counting recent orders. However, finding inactive customers may be just as important; perhaps you can learn why they’re inactive and perhaps turn them into active customers. In this article, you’ll see how to use the SQL EXISTS predicate to find missing data. This article is aimed at the Jet and Transact-SQL (T-SQL) audience. We’ll offer specific instructions when syntax or rules differ between the two dialects.
| Fast Facts |
| This article refers to Jet and Transact-SQL. The examples work in Access 97, 2000, and 2002. The T-SQL syntax is correct for SQL Server 2000. |
What Is EXISTS?
SQL’s EXISTS predicate specifies a subquery and then compares a value against the existence of one or more rows in that subquery. The subquery returns True when the subquery contains any rows and False when it doesn’t. However, all of that is probably clear as mud if you’re not familiar with subqueries.
A subquery is a SELECT query within another SELECT, INSERT, UPDATE, DELETE query, or another subquery. In other words, the subquery returns a result set, which is then subject to the main query’s conditions and criteria. Think of the subquery as a filter. The results of the embedded SELECT, also known as the inner query or inner select, become part of the search condition for the main query, otherwise known as the outer query or outer select.
The subquery can take many forms:
SELECT field1?, (subquery) AS alias FROM datasource SELECT fieldlist FROM datasource WHERE field comparison operator (subquery) SELECT fieldlist FROM datasource WHERE field ANY|SOME|ALL (subquery) WHERE expression [NOT] EXISTS (subquery)
In the preceding code, comparison operator equals one of the following: =, <>, <, >, >=, <, !>, !lt;, or <=. When you use one of these comparison operators, the subquery must return a single value. In this article, you'll work with the last form?the one that includes the EXISTS predicate.
Create a Subquery with EXISTS
When combined with EXISTS, an outer query checks for the existence of values within the inner query’s result set. Now, using the Northwind sample database that comes with Access, suppose you want to learn which companies have placed orders. The solution is simple?you don’t need a complex EXISTS solution just yet. The following query returns a unique list of companies with records in the Orders table (see Figure 1):
SELECT DISTINCT Orders.CustomerID FROM Orders
There are 89 companies that have placed at least one order (see Figure 1). The Access query displays the company name instead of the CustomerID value because the CustomerID field in the Orders table is a lookup field. A lookup field is an Access data type that displays a value other than the value that’s actually stored (SQL Server 2000 also supports lookup fields via an ADP front-end).
![]() |
|||
Figure 2).
The inner query compares the CustomerID value for each record in the Orders table to the CustomerID values in the Customers table. When a matching value is found, the inner query returns True. A True value means the customer has placed an order, but the NOT operator preceding the EXISTS predicate eliminates that particular value from the outer query’s result set. When the inner query doesn’t find any matching records, it returns False. Remember, a False value means the customer hasn’t ordered. The NOT operator then negates that False value, so the outer query can include that record in its result set. The EXISTS predicate finds values that do exist; preceding that predicate with the NOT operator finds those that don’t. Missing data can often be just as informative as data that’s available. Unfortunately, learning what’s missing isn’t always as easy as finding existing data. Combining SQL’s EXISTS predicate with the NOT operator solves the problem and quickly turns up missing information. Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience. Related PostsAbout Our Editorial ProcessAt DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere. See our full editorial policy. E-Ink Tablets Are The Focus We Need
Joe Rothwell
March 7, 2026
9:03 AM
![]() 7 Things Engineering Leaders Must Know Before Adding LLMs
Steve Gickling
March 6, 2026
9:47 PM
![]() The Essential Guide to Data Modeling for High-Write Systems
Steve Gickling
March 6, 2026
9:35 PM
![]() What Is Workload Isolation (And Why It Matters at Scale)
Rashan Dixon
March 6, 2026
9:26 PM
![]() Hybrid Retrieval vs Vector Search: What Actually Works
Kirstie Sands
March 6, 2026
9:15 PM
![]() 5 Signals Your AI Evaluation Metrics Tell the Wrong Story
Sumit Kumar
March 6, 2026
9:06 PM
![]() AI War Games Trigger Nuclear Responses
Deanna Ritchie
March 6, 2026
5:12 PM
![]() UK Regulator Fines Reddit Over Children’s Data
Kirstie Sands
March 6, 2026
3:13 PM
![]() AI Tool Records Medical Appointments Automatically
Steve Gickling
March 6, 2026
1:39 PM
![]() Rethinking The Culture Of Convenience
Sumit Kumar
March 6, 2026
1:37 PM
![]() US Rig Count Hits Four-Month Low
Steve Gickling
March 6, 2026
11:51 AM
![]() FinTech Trends: Why Debt Collection Software Is Becoming Central to AR Automation
Amelia Blackwood
March 6, 2026
10:43 AM
![]() Government iPhone Exploits Reach Cybercriminals
Sumit Kumar
March 6, 2026
9:37 AM
![]() Claude Sonnet 4.6 Narrows Gap With Opus
Rashan Dixon
March 6, 2026
9:28 AM
![]() 6 Signals Your System Is Sliding Into Operational Drift
Steve Gickling
March 5, 2026
4:56 PM
![]() Six Reasons Your AI Prototype Fails in Production
Rashan Dixon
March 5, 2026
4:46 PM
![]() 7 Early Signs Your AI Guardrails Won’t Hold in Production
Kirstie Sands
March 5, 2026
4:37 PM
![]() How to Scale Search Infrastructure for High-Query Volumes
Sumit Kumar
March 5, 2026
4:21 PM
![]() Technical Influence vs Authority in Engineering Teams
Steve Gickling
March 5, 2026
4:09 PM
![]() Optical Links Challenge Copper In Data Centers
Rashan Dixon
March 5, 2026
3:48 PM
![]() Empathy Guides Rosalyn Engelman’s Partnership
Rashan Dixon
March 5, 2026
3:25 PM
![]() Apple M5 Chips Target On-Device AI
Sumit Kumar
March 5, 2026
2:41 PM
![]() Sophia Space Raises $10 Million Seed
Steve Gickling
March 5, 2026
2:29 PM
![]() Charles Payne Hosts Investor Town Hall
Kirstie Sands
March 5, 2026
2:16 PM
![]() Xiaomi Highlights New Tech At MWC
Steve Gickling
March 5, 2026
2:13 PM
|

























