BETWEEN operator is used to test an expression within a range. Syntax of BETWEEN operator is as follows:
expr (NOT) BETWEEN begin_expr AND end_expr
-Here expr, begin_expr and end_expr is an expression which must return values.
-BETWEEN operator returns 1 if the expr is greater than or equal to begin_expr and return 0 if the expr is less than or equal to end_expr.
-NOT BETWEEN operator returns 1 if the expr is less than begin_expr and return 0 if the expr is greater than end_expr.
-BETWEEN operators return NULL if any exression is NULL.
The BETWEEN operator is typically used in the WHERE clause of SELECT, UPDATE, and DELETE statements.
Example: We have a table name 'demo' in which 'id' and 'name' are two fields. You want the record from the table whose id is in between 4 and 7. Then you will execute the query with the help of BETWEEN operator as follows: