Many common mistakes can cause unnecessary bottlenecks when you are running queries. Following is a list of these common mistakes and what to do to correct them.
SELECT IIf(ShipVia = 2, 'United Package', 'Other') AS ShipperName FROM Orders; SELECT * FROM Q1 WHERE ShipperName = 'United Package';
Because Microsoft Jet can’t optimize the IIf expression in the first query, it can’t optimize the second query. Expressions can get buried so far down in a query tree that it’s easy to forget about them. If expressions are necessary in the output, try to place the expression in a control on a form or report.
The following query replaces the previous two queries and is the optimal way to write this query:
SELECT * FROM Orders WHERE ShipVia = 2;
SELECT Orders.CustomerID, Count(Orders.OrderID) AS CountOfOrderID FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID GROUP BY Orders.CustomerID;
you may benefit by using two separate queries, as follows, where the first query is saved as SelectWithGroupByQ1:
SELECT Customers.CustomerID FROM Customers GROUP BY Customers.CustomerID; SELECT Orders.CustomerID, Count(Orders.OrderID) AS CountOfOrderID FROM SelectWithGroupByQ1, INNER JOIN Orders ON Q1.CustomerID = Orders.CustomerID GROUP BY Orders.CustomerID;