I am working on creating reports for the data contained in a large existing Access database (~ 500 mb after compactness and repair), and I am having problems with a slow subquery.
The database has a large table that contains a record of each customerβs purchase. Here is a simple query that finds customers who bought a blue widget. It completes in a few seconds and returns about ten thousand records.
SELECT DISTINCT CustomerId FROM ProductSales WHERE Product = 'BLUE'
Here is a query that is trying to find customers who bought a blue widget but not a red widget. It takes about an hour.
SELECT DISTINCT CustomerId FROM ProductSales WHERE Product = 'BLUE' AND CustomerId NOT IN ( SELECT CustomerId FROM ProductSales WHERE Product = 'RED' )
Is there a way to reorganize the second request so that it takes several minutes instead of an hour?
source share