I am running a MySQL database in rails 2.3. my model associations that I am interacting with in this query are as follows:
models: users and orders
users have 1 email
users have many orders
orders have a created at date
I want to make a list of emails from all users who have at least one order with the latest order being at least 3 months old (so, lets say today is feb 24th 2012, the last order was placed on nov 24th 2011 or earlier)
I know how to grab orders created on or before nov 24th with this query:
SELECT * FROM orders WHERE created_at <= "2011-11-24 00:00:00.000000 -08:00"
I don’t know how to find users with at least 1 order AND have those conditions for each order.
Any help would be greatly appreciated!
1 Answer