Pages

Monday 21 April 2014

SQL Between Operator

Image from => http://tapoueh.org/images/sql-logo.png

Sometimes you may need to select values thin a range in your query. SQL has a powerful operator for this kind of situations. It is the "BETWEEN" Operator. it has a very simple syntax; let discuss it with an example.

Example 1

Above query will return all customer data whose have ID is in between 1 and 100.

Example 2


This query will return all customer data whose age is not in between 45 and 50.

Example 3


Query has use another condition with between operator. It will return all customer data whose ID is in between 1 and 100 and age is 45.

Similarly you can use Numbers, text or dates as values for between operator.

Example 4

Here query will return all the products with PRODUCTNAME beginning with any of letter between 'A' and 'D'.

Example 5

Finally values used in the between operator has to be same data type as the column data type used to select range. And this operator is inclusive operator so it select the range including the given values.

You can get similar functionality by using >= and <= operator instead of between operator as follows;

Example 6

No comments:

Post a Comment