2017524 SQLBETWEENOperator
HTML CSS MORE
w3schools.com
SQL BETWEEN Operator
Previous Next
The SQL BETWEEN Operator
TheBETWEENoperatorselectsvalueswithinagivenrange.Thevaluescanbenumbers,text,ordates.
TheBETWEENoperatorisinclusive:beginandendvaluesareincluded.
BETWEEN Syntax
SELECTcolumn_name(s)
FROMtable_name
WHEREcolumn_nameBETWEENvalue1ANDvalue2;
Demo Database
Belowisaselectionfromthe"Products"tableintheNorthwindsampledatabase:
ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10boxesx20 18
bags
2 Chang 1 1 2412ozbottles 19
3 AniseedSyrup 1 2 12550ml 10
bottles
4 ChefAnton'sCajun 1 2 486ozjars 22
Seasoning
5 ChefAnton'sGumboMix 1 2 36boxes 21.35
https://www.w3schools.com/sql/sql_between.asp 1/5
2017524 SQLBETWEENOperator
HTML CSS MORE
BETWEEN Example
ThefollowingSQLstatementselectsallproductswithapriceBETWEEN10and20:
Example
SELECT*FROMProducts
WHEREPriceBETWEEN10AND20;
TryitYourself
NOT BETWEEN Example
Todisplaytheproductsoutsidetherangeofthepreviousexample,useNOTBETWEEN:
Example
SELECT*FROMProducts
WHEREPriceNOTBETWEEN10AND20;
TryitYourself
BETWEEN with IN Example
ThefollowingSQLstatementselectsallproductswithapriceBETWEEN10and20.Inadditiondonot
showproductswithaCategoryIDof1,2,or3:
Example
SELECT*FROMProducts
WHERE(PriceBETWEEN10AND20)
ANDNOTCategoryIDIN(1,2,3);
https://www.w3schools.com/sql/sql_between.asp 2/5
2017524 SQLBETWEENOperator
TryitYourself
HTML CSS MORE
BETWEEN Text Values Example
ThefollowingSQLstatementselectsallproductswithaProductNameBETWEEN'CarnarvonTigers'and
'MozzarelladiGiovanni':
Example
SELECT*FROMProducts
WHEREProductNameBETWEEN'CarnarvonTigers'AND'MozzarelladiGiovanni'
ORDERBYProductName;
TryitYourself
NOT BETWEEN Text Values Example
ThefollowingSQLstatementselectsallproductswithaProductNameNOTBETWEEN'CarnarvonTigers'
and'MozzarelladiGiovanni':
Example
SELECT*FROMProducts
WHEREProductNameNOTBETWEEN'CarnarvonTigers'AND'MozzarelladiGiovanni'
ORDERBYProductName;
TryitYourself
Sample Table
Belowisaselectionfromthe"Orders"tableintheNorthwindsampledatabase:
OrderID CustomerID EmployeeID OrderDate ShipperID
10248 90 5 7/4/1996 3
10249 81 6 7/5/1996 1
10250 34 4 7/8/1996 2
10251 84 3 7/9/1996 1
https://www.w3schools.com/sql/sql_between.asp 3/5
2017524 SQLBETWEENOperator
10252
HTML76 CSS MORE 4 7/10/1996 2
BETWEEN Dates Example
ThefollowingSQLstatementselectsallorderswithanOrderDateBETWEEN'04July1996'and'09
July1996':
Example
SELECT*FROMOrders
WHEREOrderDateBETWEEN#07/04/1996#AND#07/09/1996#;
TryitYourself
Previous Next
https://www.w3schools.com/sql/sql_between.asp 4/5
2017524 SQLBETWEENOperator
HTML CSS MORE COLOR PICKER
LEARN MORE
Tabs
Dropdowns
Accordions
ConvertWeights
AnimatedButtons
SideNavigation
TopNavigation
JSAnimations
ModalBoxes
ProgressBars
Parallax
LoginForm
HTMLIncludes
GoogleMaps
Loaders
Tooltips
Slideshow
FilterList
SortList
SHARE
CERTIFICATES
HTML,CSS,JavaScript,PHP,jQuery,BootstrapandXML.
ReadMore
https://www.w3schools.com/sql/sql_between.asp 5/5