title: sql - find users with at least 1 order AND have conditions for each order. Use count?
body: <p>I am running a MySQL database in rails 2.3. my model associations that I am interacting with in this query are as follows:</p>
  
  <p>models: users and orders</p>
  
  <p>users have 1 email</p>
  
  <p>users have many orders</p>
  
  <p>orders have a created at date</p>
  
  <p><strong>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</strong> (so, lets say today is feb 24th 2012, the last order was placed on nov 24th 2011 or earlier)</p>
  
  <p>I know how to grab orders created on or before nov 24th with this query:</p>
  
  <pre><code>SELECT * FROM orders WHERE created_at &lt;= "2011-11-24 00:00:00.000000 -08:00"
  </code></pre>
  
  <p>I don't know how to find users with at least 1 order AND have those conditions for each order. </p>
  
  <p>Any help would be greatly appreciated!</p>