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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:53:44+00:00 2026-05-13T06:53:44+00:00

As seen below the two queries, we find that they both work well. Then

  • 0

As seen below the two queries, we find that they both work well. Then I am confused why should we ever use BETWEEN because I have found that BETWEEN behaves differently in different databases as found in w3school

SELECT *
FROM employees
WHERE salary BETWEEN 5000 AND 15000;

SELECT *
FROM employees
WHERE salary >= 5000
AND salary <= 15000;
  • 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-13T06:53:45+00:00Added an answer on May 13, 2026 at 6:53 am

    BETWEEN can help to avoid unnecessary reevaluation of the expression:

    SELECT  AVG(RAND(20091225) BETWEEN 0.2 AND 0.4)
    FROM    t_source;
    
    ---
    0.1998
    
    SELECT  AVG(RAND(20091225) >= 0.2 AND RAND(20091225) <= 0.4)
    FROM    t_source;
    
    ---
    0.3199
    

    t_source is just a dummy table with 1,000,000 records.

    Of course this can be worked around using a subquery, but in MySQL it’s less efficient.

    And of course, BETWEEN is more readable. It takes 3 times to use it in a query to remember the syntax forever.

    In SQL Server and MySQL, LIKE against a constant with non-leading '%' is also a shorthand for a pair of >= and <:

    SET SHOWPLAN_TEXT ON
    GO
    SELECT  *
    FROM    master
    WHERE   name LIKE 'string%'
    GO
    SET SHOWPLAN_TEXT OFF
    GO
    
    
    |--Index Seek(OBJECT:([test].[dbo].[master].[ix_name_desc]), SEEK:([test].[dbo].[master].[name] < 'strinH' AND [test].[dbo].[master].[name] >= 'string'),  WHERE:([test].[dbo].[master].[name] like 'string%') ORDERED FORWARD)
    

    However, LIKE syntax is more legible.

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

Sidebar

Related Questions

I have a variable that contains an array from form data, seen below: $option1
I have got two models, seen below, and am trying to insert one of
What is the benefit of having two try-catch as seen below? Taken from the
I have seen below two lines in a shell script. Im new to unix
The code below plots some simple x-y data, but it has two problems that
I've seen (and done) data source configuration in two ways (the code below is
I have a Perl script which nests foreach loops as seen below. It takes
I have an XML document containing contact information as seen below: <contact type=individual> <firstname>Some</firstname>
I have a long function, as seen below: hash_correct = hashlib.md5(salt + password)).digest().encode(base64) I'd
In my MongoDB, I have Document1, as seen below. I want to reach into

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.