SQL BETWEEN Operator

SQL BETWEEN Operator

SQL BETWEEN Operator  - The SQL BETWEEN operator is used to returns records match between two values in WHERE  Condition.

The range of value should be text, numbers or dates.

In last sql post we leaned LIKE Operator and  SQL IN Operator. In this sql tutorial we will learn SQL BETWEEN Operator with syntax and example.

The SQL BETWEEN Operator Syntax :

SELECT  col1, col2 FROM  table_name WHERE  col1 BETWEEN val1 and val2

Above sql query returns all records whose col1 value from val1 to val2.

 

The SQL BETWEEN Operator Example:

Here, we have table Student and we want to select records whose id start from 2 to 4.
Here, we need to make sql query which returns student whose id between 2 to 4.

Here, we have table Student with below records.

The SQL Student Table :

ID Name City Email
1 Meera Bombay meera@yahoo.com
2 Ram Surat ram@yahoo.com
3 Manoj Bombay manoj@yahoo.com
4 Vaidehi Ahmedabad meera@yahoo.com

SELECT * FROM Student WHERE ID BETWEEN  2 and 4

The Result of SQL BETWEEN Operator is :

ID Name City Email
2 Ram Surat ram@yahoo.com
3 Manoj Bombay manoj@yahoo.com
4 Vaidehi Ahmedabad meera@yahoo.com

 

Leave a Reply

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

6 + 9 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">