SQL BETWEEN

Example Data Table : Orders (All of the below examples use this table as datasource)
OrderNo CustomerName SalePrice Quantity OrderDate
20101213095 John 3500 10 2010-12-13
20100620135 Jimmy 2509 22 2010-06-20
20100620392 Vincent 7200 5 2010-06-20
20100530006 Tyler 9200 50 2010-05-30
20100515029 Alan 100 50 2010-05-29


Example
Select rows between two dates
 
Sytax : SELECT * FROM table_name WHERE column_name BETWEEN date1 AND date2
SQL
SELECT * FROM Orders WHERE OrderDate BETWEEN '2010-05-01' AND '2010-05-30'

will output
OrderNo CustomerName SalePrice Quantity OrderDate
20100530006 Tyler 9200 50 2010-05-30
20100515029 Alan 100 50 2010-05-29


Example
Select rows between two different values
 
Sytax : SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2
SQL
SELECT * FROM Orders WHERE OrderDate BETWEEN 5000 AND 10000

will output
OrderNo CustomerName SalePrice Quantity OrderDate
20100620392 Vincent 7200 5 2010-06-20
20100530006 Tyler 9200 50 2010-05-30
comments powered by Disqus