MySQL BETWEEN Operators with WHERE Condition

We learn to mysql between datetime, between date range, between inclusive, between timestamp, between two times, between exclusive, between vs greater than, select data between two dates in mysql or many more.

MySQL BETWEEN with number

SELECT 
    itemCode, 
    itemName, 
    subscribeAmount
FROM
    items
WHERE
    subscribeAmount BETWEEN 90 AND 100;              

This query uses the greater than or equal (>=) and less than or equal ( <= ) operators instead of the BETWEEN operator to get the same result: MySQL WHERE Clause With AND, OR, IN, NOT IN

SELECT 
    itemCode, 
    itemName, 
    subscribeAmount
FROM
    items
WHERE
    subscribeAmount >= 90 AND subscribeAmount <= 100;

To find the item whose buy amount is not between $20 as well as $100, you combine the BETWEEN operator with the NOT operator as follows:

SELECT 
    itemCode, 
    itemName, 
    subscribeAmount
FROM
    items
WHERE
    subscribeAmount NOT BETWEEN 20 AND 100;

You can rewrite the query above using the less than (<), greater than (>), and logical operators ( AND) as the following query:

SELECT 
    itemCode, 
    itemName, 
    subscribeAmount
FROM
    items
WHERE
    subscribeAmount < 20 OR subscribeAmount > 100;            

MySQL WHERE Clause With AND, OR, IN, NOT IN

BETWEEN with dates

SELECT 
   stockNumber,
   requiredDate,
   is_check
FROM 
   stocks
WHERE 
   requireddate BETWEEN 
     CAST('2021-01-01' AS DATE) AND 
     CAST('2021-01-31' AS DATE);

I hope you get an idea about BETWEEN Operator Explained By Practical Examples.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment