Sql BETWEEN and NOT BETWEEN operators

Sql BETWEEN and NOT BETWEEN operators

Blog Bustle 23/03/2020

Sql between operator is used to select values between two values. These values are of same data types and from same sql column. Sql Between operator includes first value and last value. These values can be text, dates or numbers. Sql Between operator is used with select sql query.

Syntax

Sql Between operator syntax

SELECT * from table_name
WHERE column_name BETWEEN value_1 and value_2;

Sql Not Between operator syntax

SELECT * from table_name
WHERE column_name NOT BETWEEN value_1 and value_2;

These are the basic syntax of Sql Between and Not Between operators.

Let's look at some examples to understand sql between and not between operators.

I have sql table named student_register.

id name class admission_fee dob
1 justin 6 600 2011-03-06
2 robin 7 700 2010-04-18
3 jessie 9 900 2008-07-01
4 chris 8 800 2009-09-04

Find those students record whose admission fee is between $700 and $900 and sql query will be

SELECT * from student_register WHERE admission_fee Between 700 and 900;

After running this sql query, result will be

id name class admission_fee dob
2 robin 7 700 2010-04-18
3 jessie 9 900 2008-07-01
4 chris 8 800 2009-09-04

Find those students record whose date of birth between 2009-01-01 and 2010-01-01 and sql query will be

SELECT * from student_register WHERE dob Between '2009-01-01' and '2010-12-31';

After running this sql query, result will be

id name class admission_fee dob
2 robin 7 700 2010-04-18
4 chris 8 800 2009-09-04

Find those students record whose admission fee is not between $600 and $800 and sql query will be

SELECT * from student_register WHERE admission_fee NOT Between 600 and 800;

After running this sql query, result will be

id name class admission_fee dob
3 jessie 9 900 2008-07-01

After looking at these examples, we can easily use sql between and not between operators. Hope you like this tutorial.

Other important links

Sql Limit clause

Sql Order By clause

Sql Aggregate Functions

Sql NOT IN operator

Sql IN operator

Sql BETWEEN and NOT BETWEEN operators searches:

Tags: #mysql