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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:17:46+00:00 2026-06-12T09:17:46+00:00

I have a query for selecting orders and I want to select between two

  • 0

I have a query for selecting orders and I want to select between two dates. But I also want to select all orders that are of one of 3 or 4 statuses. I have the following

SELECT *
WHERE  created BETWEEN '1296360000' AND '1322884800'
       AND order_status = 'pending'
        OR order_status = 'processing'
        OR order_status = 'payment_received'
        OR order_status = 'completed' 

But the problem is it seems to select everything with order status of one of those 4. And completely ignores the BETWEEN if I change the order of the BETWEEN to be after the order status OR‘s it still includes orders with a created timestamp after the '1322884800'

Where should I put the between or how can I do this to select orders between X and Y with a order status of one of 4 (or 3, or 2, or 1) value(s)?

  • 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-06-12T09:17:46+00:00Added an answer on June 12, 2026 at 9:17 am

    Put the order_status clause in parentheses (or better yet, use an IN list).

    SELECT *
    WHERE  created BETWEEN '1296360000' AND '1322884800'
           AND (order_status = 'pending'
            OR order_status = 'processing'
            OR order_status = 'payment_received'
            OR order_status = 'completed')
    

    The way you have it now, the precedence is being interpreted as:

    SELECT *
    WHERE  (created BETWEEN '1296360000' AND '1322884800'
           AND order_status = 'pending')
            OR order_status = 'processing'
            OR order_status = 'payment_received'
            OR order_status = 'completed' 
    

    This would evaluate to true if any of the last three order status are found, regardless of the created date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query (notice that all 3 subqueries are selecting different columns from
I have a little problem with a query. I'm selecting data using the between
I have query to show the table like this: but I want to PIVOT
I have the follow query selecting stuff from a database: mysql_query(SELECT * FROM categories
I have a query where I'm selecting the number of users that have submitted
I have two tables. One is items , and one is tags . Query's
I want to create a veiw and then select from it in one query,
I have two MySQL questions. $query = " SELECT stationname FROM stations WHERE stationname
I have a complicated MySQL query which takes a lot of time, selecting from
I have a simple SQL query: Select ID, COUNT(ID) as Selections, OptionName, SUM(Units) as

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.