sql between statement

The SQL between statement is used to extract some different information from the middle of a data. SQL between works according to the condition as if you want to extract data by numbers or by dates. Let’s know how to use between in SQL.

SQL Between Statement

We have a table of Employees from within which we have extract Employees from 20 to 80 years of age.

/ ***** Employees with age ranging from 20 to 80 extract ***** /

SELECT * FROM Employees
WHERE age BETWEEN 20 AND 80;

/ ***** Employees with salary ranging from 2000 to 6000 extract ***** /

SELECT * FROM Employees
WHERE salary BETWEEN 2000 AND 6000;

/ ***** Employees with employeeID ranging from 2 to 7 extract ***** /

SELECT * FROM Employees
WHERE employeeID BETWEEN 2 AND 7;


/ ***** Employees with joinDate ranging from 2009 to 2019 extract ***** /

SELECT * FROM Employees
WHERE joinDate BETWEEN 15-2-2009 AND 10-2-2019;

/ ***** Employees with age ranging from abc to tuv extract ***** /

SELECT * FROM Employees
WHERE name BETWEEN abc AND tuv;
EmployeeIDNameAgeSalaryJoinDate
1abc20200019-2-2020
2efg30540010-2-2019
3hij40560016-4-20015
4klm50360010-5-2004
5nop60240015-2-2009
6qrs70570010-6-2018
7tuv80800025-12-2016
8wxy90980010-7-2005
9zzz100520030-9-2014

SQL Not Between

The SQL Not Between statement is used to extract different information outside the data range. Let’s know how to use not between in SQL.

/ ***** Removed those whose age is between 40 and 80 ***** /

SELECT * FROM Employees
WHERE age NOT BETWEEN 40 AND 80;

/ ***** Removed those whose salary is between 5000 and 8000 ***** /

SELECT * FROM Employees
WHERE salary NOT BETWEEN 5000 AND 8000;

/ ***** Removed those whose employeeID is between 3 and 8 ***** /

SELECT * FROM Employees
WHERE employeeID NOT BETWEEN 3 AND 8;


/ ***** Removed those whose joinDate is between 2009 and 2019 ***** /

SELECT * FROM Employees
WHERE joinDate NOT BETWEEN 15-2-2009 AND 10-2-2019;

/ ***** Removed those whose age is between efg and wxy ***** /

SELECT * FROM Employees
WHERE name NOT BETWEEN efg AND wxy LIMIT 4;
EmployeeIDNameAgeSalaryJoinDate
1abc20200019-2-2020
2efg30540010-2-2019
3hij40560016-4-20015
4klm50360010-5-2004
5nop60240015-2-2009
6qrs70570010-6-2018
7tuv80800025-12-2016
8wxy90980010-7-2005
9zzz100520030-9-2014

Single Record

But if you want to extract only one record instead of extracting the data of the whole table, then for that you have to follow the example shown below.

/ ***** Extracted only the Employee whose salary is 2000 to 6000 ***** /

SELECT salary FROM Employees
WHERE salary BETWEEN 2000 AND 6000;
/ ***** Extracted only the Employee whose age is 30 to 90 ***** /

SELECT age FROM Employees
WHERE age BETWEEN 30 AND 90;

/ ***** Extracted only the Employee whose joinDate is 2016 to 2019 ***** /

SELECT joinDate FROM Employees
WHERE joinDate BETWEEN 10-2-2016 AND 25-12-2019;

Multi Data Record

If you want to extract a multi-data record from your table with SQL between statement, follow the example shown below for that.

/ ***** This record was extracted according to join date ***** /

SELECT name, age, salary FROM Employees
WHERE joinDate BETWEEN 10-2-2016 AND 25-12-2019;

/ ***** This record was extracted according to salary ***** /

SELECT name, age FROM Employees
WHERE salary BETWEEN 3000 AND 6000;

/ ***** This record was extracted according to age ***** /

SELECT name, salary FROM Employees
WHERE age BETWEEN 20 AND 70;

SQL Keywords

We have some keywords of SQL available, which are used most commonly. Let’s know what those keywords are and what they mean.

NoKeywordsDescription
1CREATEIt is used to create a database and table
2CREATE DATABASEIt is used to create a database only
3CREATE TABLEIt is used to create a table
4DELETEIt is used to delete record from the table
5DROPIt is used to delete a column, database, and table
6DROP COLUMNIt is used to delete a column in the table
7DROP TABLEIt is used to delete a table
8FOREIGN KEYIt is used to join two tables together
9JOINIt is used to join the tables
10UPDATEIt is used to update the record in the table

Note: All the examples you have seen inside this article have all been made by us and tested thoroughly. So you can use all these without any difficulty.

Read Also: 5 Javascript Replace Method you must know