MySQL: cláusula entre

Puedes usar BETWEEN cláusula para reemplazar una combinación de condiciones "mayor que igual Y menor que igual".

Comprender BETWEEN cláusula, considere una employee_tbl tabla, que tiene los siguientes registros:

mysql> SELECT * FROM employee_tbl;
+------+------+------------+--------------------+
|  id  | name | work_date  | daily_typing_pages |
+------+------+------------+--------------------+
|   1  | John | 2007-01-24 |        250         |
|   2  | Ram  | 2007-05-27 |        220         |
|   3  | Jack | 2007-05-06 |        170         |
|   3  | Jack | 2007-04-06 |        100         |
|   4  | Jill | 2007-04-06 |        220         |
|   5  | Zara | 2007-06-06 |        300         |
|   5  | Zara | 2007-02-06 |        350         |
+------+------+------------+--------------------+
7 rows in set (0.00 sec)

Ahora, suponga que, basándose en la tabla anterior, desea obtener registros con condiciones daily_typing_pages más de 170 e igual y menos de 300 e igual. Esto se puede hacer usando>= y <= condiciones de la siguiente manera:

mysql>SELECT * FROM employee_tbl 
   ->WHERE daily_typing_pages >= 170 AND
   ->daily_typing_pages <= 300;
+------+------+------------+--------------------+
|  id  | name | work_date  | daily_typing_pages |
+------+------+------------+--------------------+
|   1  | John | 2007-01-24 |        250         |
|   2  | Ram  | 2007-05-27 |        220         |
|   3  | Jack | 2007-05-06 |        170         |
|   4  | Jill | 2007-04-06 |        220         |
|   5  | Zara | 2007-06-06 |        300         |
+------+------+------------+--------------------+
5 rows in set (0.03 sec)

Lo mismo se puede lograr usando BETWEEN cláusula de la siguiente manera:

mysql> SELECT * FROM employee_tbl 
   -> WHERE daily_typing_pages BETWEEN 170 AND 300; 
+------+------+------------+--------------------+
|  id  | name | work_date  | daily_typing_pages |
+------+------+------------+--------------------+
|   1  | John | 2007-01-24 |        250         |
|   2  | Ram  | 2007-05-27 |        220         |
|   3  | Jack | 2007-05-06 |        170         |
|   4  | Jill | 2007-04-06 |        220         |
|   5  | Zara | 2007-06-06 |        300         |
+------+------+------------+--------------------+
5 rows in set (0.03 sec)
mysql-funciones-útiles.htm