SQL Keyword BETWEEN

The BETWEEN keyword is used to select values within a given range, which can be numbers, text, or dates.

  • Always the beginning and end values of a range are included.

BETWEEN Number Range

The below SQL fetches products having prices between the specified number range.

Run this on IDE

SELECT * FROM products
WHERE price BETWEEN 10 AND 20;

BETWEEN Strings

The below SQL fetches employees having names between the specified string range.

SELECT * FROM employees 
WHERE employee_name BETWEEN 'Arun' AND 'Kumar';

BETWEEN Dates

The below SQL fetches employees having birth dates between the specified date range.

SELECT * FROM employees 
WHERE birth_date BETWEEN CAST('1990-01-01' AS DATE) AND CAST('2020-01-01' AS DATE);

NOT BETWEEN

The below SQL fetches products not having prices between the specified number range.

SELECT * FROM products
WHERE price NOT BETWEEN 10 AND 20;

Related Links