SQL Between Operator Example
Let’s look at some examples of BETWEEN Operator in SQL, to understand how to use BETWEEN operators in SQL:
First, we need to create a new database and a table inside the database. We will then use the BETWEEN operator in SQL query.
Demo Database
CREATE DATABASE w3wiki;
USE w3wiki;
CREATE TABLE STUDENTS(
STUDENT_ID INT PRIMARY KEY,
NAME VARCHAR(20),
ADDRESS VARCHAR(20),
AGE INT,
DOB DATE);
INSERT INTO STUDENTS VALUES
(1, 'DEV', '120', 2001, '2001-03-09'),
(2, 'AMAN', '92', 2003, '2003-11-28'),
(3, 'VINOD', '184', 2002, '2002-09-16'),
(4, 'YASH', '87', 2001, '2001-06-18'),
(5, 'NITYA', '195', 2000, '2000-01-12');
SELECT * FROM STUDENTS;
Output:
SQL BETWEEN Example
In this example, we will display the details of students having TOTAL_MARKS between 100-200 and DOB between 2001-01-01 and 2003-01-01.
Query:
SELECT *
FROM STUDENTS
WHERE TOTAL_MARKS BETWEEN 100 AND 200 AND DOB BETWEEN "2001-01-01" AND "2003-01-01";
Output:
SQL BETWEEN Operator
SQL BETWEEN operator select the value in the given range, including the start and end values.
Contact Us