MySQL

MySQL BETWEEN

The BETWEEN operator is a logical operator that allows you to specify whether a value is in a range or not. The BETWEEN operator is often used in WHERE clause with statements such as SELECT, UPDATE and DELETE.
 

Syntax:

The syntax of BETWEEN operator in MySQL is as follows:

expression BETWEEN value1 AND value2;
 
Let’s take a few examples of using BETWEEN operator to see how it works. For this we will use the “Clients” table.
 

 
The following query will display all rows in the client table where the age is between 20 and 30 (inclusive).

SELECT *
FROM Clients
WHERE Age BETWEEN 20 AND 30;


 

 
The following SELECT statement is the same as the above statement:

SELECT * FROM Clients WHERE Age >= 20 AND Age <= 30;


 
The following example uses the BETWEEN operator to extract the values between two dates.

SELECT *
FROM Orders
WHERE order_date BETWEEN CAST('2020-06-01' AS DATE) AND CAST('2020-06-30' AS DATE);

When using the BETWEEN operator in MySQL with dates, be sure to use the CAST function to explicitly convert values to dates.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *