MySQL: BETWEEN Operator

Profile picture for user arilio666

The BETWEEN operator fetches the information of values of a table from within a range of other values. To put it simply it fetches the in-between range we provide as the condition in the query.

Syntax

SELECT * from TableName WHERE ColumnName BETWEEN 'value1' and 'value2'

We can also negate the within range values neglecting that part of the data and fetching information with NOT.

SELECT * from TableName WHERE ColumnName NOT BETWEEN 'value1' and 'value2'

Today we will be using the orders table to get the order details which has happened between the year 2018 to 2020.

Example

select * from orders where order_date BETWEEN '2018-01-01' AND '2020-01-01'

So as we can see it fetched the order details between the date of 2018 to 2020 which generally means the information of what has happened between these periods and this BETWEEN operator displayed it with ease.

Tags