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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Laravel get months between two dates
  2.   laravel middleware check custom header for REST API
  3.   Laravel Increment and Decrement Example
  4.   Laravel Email Verification Script Example
  5.   Laravel clear cache from route, view, config and all cache
  6.   Upload Multiple Images Preview using PHP
  7.   what does pairwise distinct mean?
  8.   Different Types of SQL Keys in Database with Example
  9.   Fetch Last week month year records in MySQL
  10.   laravel Redirect jQuery ajax success
Tags:, , , , , ,