blog post

WHERE BETWEEN returns values that fall within a given range.
WHERE BETWEEN is a shorthand for >= AND <=.
BETWEEN operator is inclusive: begin and end values are included.

SQL WHERE BETWEEN Examples

Problem: List all products between $10 and $20
SELECT Id, ProductName, UnitPrice
  FROM Product
 WHERE UnitPrice BETWEEN 10 AND 20
 ORDER BY UnitPrice

Problem: List all products not between $10 and $100 sorted by price.
SELECT Id, ProductName, UnitPrice
  FROM Product
 WHERE UnitPrice NOT BETWEEN 5 AND 100
 ORDER BY UnitPrice

Problem: Get the number of orders and amount sold between Jan 1, 2018 and Oct 18, 2016.
SELECT COUNT(Id), SUM(TotalAmount) FROM [Order] WHERE OrderDate BETWEEN '1/1/2016' AND '10/18/2016'

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information