Quote Originally Posted by DrByte View Post
The logic of the following query is:
"get distinct products_id values from the list of all has-been-purchased-at-least-once products, where the purchase date is more than 90 days ago"

Code:
"SELECT distinct products_id from " . TABLE_ORDERS_PRODUCTS . " op 
JOIN " . TABLE_ORDERS . " o ON o.orders_id = op.orders_id AND o.date_purchased > DATE_SUB(CURDATE(), INTERVAL 90 DAY)";
I think the logic needs to be the following:

"get distinct products_id values from the list of all has-been-purchased-at-least-once products, where the product HASN'T BEEN PURCHASED WITHIN 90 DAYS."

Like lruskauff mentioned above, your query WILL return products purchased greater than 90 days. However, we are missing one extra query, and that is "The products returned must also NOT HAVE BEEN purchased within 90 days as well."

That is the missing factor here, and the one we are all trying to figure out how best to write the query. Any ideas?