Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:28:22+00:00 2026-05-30T11:28:22+00:00

I am running a MySQL database in rails 2.3. my model associations that I

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:28:24+00:00Added an answer on May 30, 2026 at 11:28 am
    SELECT users.email
    FROM users
      JOIN
        ( SELECT user_id, MAX(created_at) AS created_at
          FROM orders
          GROUP BY user_id
          HAVING MAX(created_at) < CURDATE() - INTERVAL 3 MONTH
        ) AS oo
        ON oo.user_id = users.id
    ORDER BY oo.created_at DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Rails application that is running in a MySQL master-slave set-up for
I'm using Subsonic 3.0.0.3 with ActiveRecord, running against a MySQL database. I'm finding that
I have a mysql database filled up and running on a Windows computer, is
I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT *
I get this error when running rails with mysql db. Basically it is not
I am running ruby 1.8.7, rails 2.3.5 and mysql database. The record in mysql
I'm using Rails 3.2 and have a migration that contains the code: add_column :users,
I exported a live MySQL database (running mysql 5.0.45) to a local copy (running
I'm running a MySQL database locally for development, but deploying to Heroku which uses
I'm trying to move a MySQL database from a Linux machine to one running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.