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

The Archive Base Latest Questions

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

Query 1 works but query 2 doesn’t: Query #1: SELECT * FROM `users` WHERE

  • 0

Query 1 works but query 2 doesn’t:

Query #1:

SELECT * FROM `users` WHERE users.dob <= '1994-1-14' AND users.dob >= '1993-1-14' LIMIT 10

Query #2:

SELECT * FROM `users` WHERE users.dob BETWEEN '1994-1-14' AND '1993-1-14' LIMIT 10

The 2nd one should be able to do the same thing as the first but I don’t understand why it’s not working.

The dob (date of birth) field in the users table is a type date field with records that look like this:

1988-11-08  
1967-11-14  
1991-03-09      
1958-03-08  
1967-06-30  
1988-10-19   
1986-01-23  
1965-09-20

YEAR – MONTH – DAY

With either query #1 or #2 I’m trying to get back all users who are between 18 and 19 years of age, because 1994-1-14 is exactly 18 years from today and 1993-1-14 is 19 years from today. So is there a way to get the between query to work?

By not working I mean it doesn’t return any records from the db while the working query does.

Also is the between query more efficient or is the performance difference negligible?

  • 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-28T11:00:19+00:00Added an answer on May 28, 2026 at 11:00 am

    The usage is wrong. See the BETWEEN documentation:

    expr BETWEEN min AND max is equivalent to (min <= expr AND expr <= max).

    Therefore, users.dob BETWEEN '1994-1-14' AND '1993-1-14' is the same as ('1994-1-14' <= users.dob AND users.dob <= '1993-1-14'), of which there will never be more than 0 results.

    Simply reverse the order 🙂

    There will be no performance difference when using either form, possibly subject to the note below. This transformation happens at the query planner level. However, if you have concerns, remember to profile, profile, profile. Then you can see for yourself and appease the premature-optimization demons.


    Also note the … note:

    For best results when using BETWEEN with date or time values, use CAST() to explicitly convert the values to the desired data type.

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

Sidebar

Related Questions

The following query works on Oracle 10.2.0.1.0 on windows,but doesn't work on Oracle 10.2.0.2.0
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
I have a query that works on MySQL but doesn't work on Oracle, and
I have this query that works: select name, location_id from all_names where location_id in
I have the following Oracle query SELECT * FROM table WHERE date_opened BETWEEN ((TO_DATE('2011-08-01',
This query works: SELECT u.UserId, u.GroupId, u.username, gp.PreferenceId, gp.Properties, gp.Override FROM dbo.UserTable u Inner
I have a query that works on Postgresql 7.4 but not on Postgresql 8.3
I have the following query which works fine with MySQL but refuses to work
I have a query which works fine in MySQL, but when I run it
I have written a SQL query that works just fine, but am having a

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.