* Get a list of all customers and include orders in a * particular month. * Here's the incorrect version SELECT CompanyName, OrderDate; FROM Customers ; LEFT JOIN Orders ; ON Customers.CustomerID = Orders.CustomerID ; WHERE OrderDate BETWEEN {^ 1996-9-1} AND {^ 1996-9-30} ; INTO CURSOR OrdersAllCustomersIn this example, you end up with only the customers who placed an order in the specified month.
* Here's the working version with the filter condition * in the join clause SELECT CompanyName, OrderDate; FROM Customers ; LEFT JOIN Orders ; ON Customers.CustomerID = Orders.CustomerID ; AND OrderDate BETWEEN {^ 1996-9-1} AND {^ 1996-9-30} ; INTO CURSOR OrdersAllCustomersWhat happens in the first case is that you get all the customers along with their orders. Then all orders that aren't in the specified month get filtered out. That includes any records that were added by the outer join and thus have a null order date. It also removes customers who have orders, but not in that month.