Posted inMysql / Mysqli / php

how to use between in sql

Today, We want to share with you how to use between in sql.In this post we will show you sql query between two dates and times, hear for sql between two dates inclusive we will give you demo and example for implement.In this post, we will learn about sql between inclusive with an example.

sql between datetime

In this tutorial we learn to all about how to use between in sql Examples like as a SQL BETWEEN Operator, BETWEEN with IN, BETWEEN Text Values, BETWEEN Dates or many more.

Also Read: MySQL BETWEEN Operators with WHERE Condition

SQL BETWEEN Operator

SELECT * FROM Mobiles
WHERE Amount BETWEEN 10 AND 20;

NOT BETWEEN Example

SELECT * FROM Mobiles
WHERE Amount NOT BETWEEN 10 AND 20;

BETWEEN with IN Example

SELECT * FROM Mobiles
WHERE Amount BETWEEN 10 AND 20
AND CategoryID NOT IN (1,2,3);

BETWEEN Text Values Example

SELECT * FROM Mobiles
WHERE MobileName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
ORDER BY MobileName;
SELECT * FROM Mobiles
WHERE MobileName BETWEEN "Carnarvon Tigers" AND "Chef Anton's Cajun Seasoning"
ORDER BY MobileName;

NOT BETWEEN Text Values Example

SELECT * FROM Mobiles
WHERE MobileName NOT BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
ORDER BY MobileName;

BETWEEN Dates Example

SELECT * FROM Requets
WHERE OrderDate BETWEEN #01/07/1996# AND #31/07/1996#;
SELECT * FROM Requets
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';

SQL WHERE BETWEEN Examples

SELECT Id, MobileName, TotalPrice
  FROM Mobile
 WHERE TotalPrice BETWEEN 10 AND 20
 ORDER BY TotalPrice

Using BETWEEN with Numeric Values

SELECT Fname, Lname
FROM Member
WHERE Salary
BETWEEN 30000 AND 45000;

Using BETWEEN with Date Values:

SELECT Fname, Lname
FROM Member
where DOB
BETWEEN '1985-01-01' AND '1990-12-30';

Using NOT operator with BETWEEN

SELECT Fname, Lname
FROM Emplyoee
WHERE Salary
NOT BETWEEN 30000 AND 45000;

Example – Using NOT Operator

SELECT *
FROM members
WHERE member_id NOT BETWEEN 2000 AND 2999;

SQL query to select dates between two dates

select Date, TotalAllowance from Calculation where MemberId = 1
             and Date between '2021/02/25' and '2021/02/27'

OR

select Date, TotalAllowance from Calculation where MemberId = 1
             and Date >= '2021/02/25' and Date <= '2021/02/27'

I hope you get an idea about how to use between in sql.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype