I have an order database. Each order can have multiple SKUs on the order. Likewise, SKUs can be attached to multiple orders. Each order has a date field that stores the date it was created.
- Table1 = Details table which stores all the SKU information attached to order
- Table2 = Summary that lists Order ID and ship date which cross reference with Table1 to get more detail of each order
What I am trying to find is SKUs that aren’t attached to any orders after a certain date. In other words, I want a list of SKUs that haven’t been ordered in the last 30 days.
It seems that NOT BETWEEN should work, but it keeps returning SKUs that have been on orders past 7/21/2012. Here is the query I am using:
SELECT DISTINCT table1.sku, table2.ship_date
FROM table1, table2
WHERE table1.orderID = table2.orderID
AND table2.ship_date NOT BETWEEN DATE ('2012-07-21') and DATE('2012-08-23')
ORDER BY table1.ship_date ASC;
Any help will be very appreciated.
You need to use
not inand base it on the sku table:This query will also return SKUs that have never been ordered.