Home  >  Article  >  Database  >  Detailed explanation of usage examples of BETWEEN clause in MySQL

Detailed explanation of usage examples of BETWEEN clause in MySQL

怪我咯
怪我咯Original
2017-07-05 11:09:331562browse

This article mainly introduces the detailed usage of the BETWEEN clause in MySQL. It is the basic knowledge for MySQL entry. Friends who need it can refer to it. Next

You can use the IN clause instead of combining the "greater than or equal to and less than or equal to" conditions.

To understand the EMPLOYEE_TBL table considered by the BETWEEN clause, the EMPLOYEE_TBL table has the following records:

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)

Now, suppose that according to the above table, you want to obtain the record condition daily_typing_pages exceeds 170, is equal to and is less than 300. This can be achieved using the following conditions >= and <=

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)

can also be achieved using the BETWEEN clause as follows:

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)

The above is the detailed content of Detailed explanation of usage examples of BETWEEN clause in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn