Learn From - Interactive SQL



SQL BETWEEN Operator


The Between operator is used to get range of values between two specified values. This can be used for values that are text, number and date.

SQL BETWEEN Operator Syntax


SELECT column_name1, column_name2 ... FROM table_name WHERE column_name BETWEEN value1 AND value2

Below is shown the "Orders" table:

OrderID CustomerID Date Amount
D001 C001 4/3/2007 12:00:00 AM 150.23
D002 C003 1/22/2005 12:00:00 AM 123.57
D003 C005 3/19/2003 12:00:00 AM 220.43
D004 C007 7/21/2008 12:00:00 AM 157.72
D005 C008 2/28/2009 12:00:00 AM 223.78
D006 C011 3/21/2005 12:00:00 AM 245.34

SQL BETWEEN Operator Example


Text Editor below has the SQL Query, click the "View Result" button, to see the result.

To retrieve all the records between the year 2005 and 2010 from the Orders table.

Select * from Orders
where Date between '1-Jan-2005' and '1-Jan-2010'
Order by Date;

To retrieve all the customer IDs between the values 'C005' and 'C008' from the Orders table.

Select * from Orders
where CustomerID between 'C005' and 'C008';

SQL in Text Editor: