Sql Between

With Sql Between, it is very convenient to select a range of data between two values.


The values selected are inclusive. It is the same as using greater & equal (>=)and less & equal (<=) operators all together.

Note: If your intension is to get an exclusive range, then use the greater than (>) and less than operators (<).

 

 

 

 

The syntax:

SELECT  column_list
FROM table_name
WHERE column_name [NOT] BETWEEN value1 AND value2

Where Arguments

column_name
Any column in the table. You can also use an expression.

NOT
Specifies that the result of the predicate be negated.

value1 and value2
Are any valid expression and must have the same data type as the column_name.

AND
A placeholder to indicate that column_name should be within the range indicated by value1 and value2.

Example: For better understanding of Sql Between, let's use the following Expenses table to illustrate. Find out what items that cost between 3 and 8 dollar.

ExpIdDateDescriptionCategoryAmount
10011/07/2009 12:00:00 AMLong Black Coffee13.00
10021/07/2009 12:00:00 AMNewspaper51.00
10031/07/2009 12:00:00 AMMorning Tea14.00
10041/07/2009 12:00:00 AMLunch18.00
10051/07/2009 12:00:00 AMDinner112.00
10061/07/2009 12:00:00 AMMagazine PC World511.00

SQL Statement:

SELECT *
FROM Expenses
WHERE  Amount BETWEEN 3 AND 8

Result:

ExpIdDateDescriptionCategoryAmount
10011/07/2009 12:00:00 AMLong Black Coffee13.00
10031/07/2009 12:00:00 AMMorning Tea14.00
10041/07/2009 12:00:00 AMLunch18.00

Quick link. From here, you can learn the following:

Sql Select
The core of Sql, selecting data from table.

Sql Where
Conditionally selecting rows from table.

Sql Distinct
Eliminating duplicate values in the output.

Sql Count
Counting number of rows.

Sql Sum
Getting the sum of a field

Sql Max
This function will return the highest value.

Sql Min
This function will return the lowest value.

Sql Avg
This function will return the average value.

Sql Order By
Sorting the output

Sql And Or
Connecting two or more conditions in the Where or Having clause.

Sql Group By
Grouping rows into sets.

Sql Having
To filter the result of aggregation

Sql Like
Pattern searching for conditions in Where or Having clause

Couldn't find what you're looking for? Use this search feature to quickly find it!

Positive Resources

All of us have at least two or three things that excite us. We could talk about these subjects for hours. Good news!. Did you know that Site Built It! can turn this type of deep interest and enthusiasm into a revenue-generating business?

Review some of the Site Build It! case studies and you'll absolutely discover something that ignites more positive ideas into your mind.

SBI! Video Tour


Invest the most
important 30 minutes
you will spend online.

Click, sit back, and
understand why SBI!
makes you succeed.