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 6323355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:30:05+00:00 2026-05-24T16:30:05+00:00

I have an ecommerce MySQL database that stores order information in the table ‘orders’

  • 0

I have an ecommerce MySQL database that stores order information in the table ‘orders’

I need to select all NEW customers for the month of March. Customers do not have to register to order, so I’m working simply with the customer email and the date time of the order. So select all customer emails that don’t feature at all in previous months.

The database table has about 100k rows, and I’m looking for an efficient query.

I’m not too good with SQL (you can probably tell!), but this is what I have…

SELECT distinct(user_email) FROM orders
WHERE order_datetime > '2011-03-01 00:00:00' 
      AND order_datetime < '2011-03-31 23:59:59' 
      AND user_email NOT IN (
          SELECT user_email FROM orders 
          WHERE order_datetime < '2011-03-01 00:00:00')
GROUP BY user_email

Is that a really convoluted way of doing things? 🙂 Please let me know if there’s a more speed efficient way…

Thanks, Rich

  • 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-24T16:30:06+00:00Added an answer on May 24, 2026 at 4:30 pm

    How about this:

     SELECT user_email
     FROM orders     
     GROUP BY user_email
     HAVING MIN(order_datetime) BETWEEN '2011-03-01' AND '2011-03-31 23:59:59';
    
    • the first order being in March is checked in the HAVING clause.
    • having an index on order_datetime will help.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP/MySQL e-commerce site that is placing order detail information into a
I have a simple ecommerce type site that will have users with accounts, orders,
I have an PHP/MySQL eCommerce application that has a few innoDB tables (for the
I have a database for an E-commerce storefront. MSSQL 2008. I have a table
I have an ecommerce website that works in a classical way: people sign up,
Lets say I have a simple ecommerce site that sells 100 different t-shirt designs.
I have been tasked with designing an ecommerce solution. The aspect that is causing
I have a table row with 4 columns on my ecommerce site and I
I'm a designer (starting to learn PHP/MySQL) and am need in an eCommerce platform
Why do some ecommerce database have tables: product product_variant Why not only one product

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.