The usage of between clause in Mysql is detailed _mysql

Source: Internet
Author: User

You can use the IN clause instead of the combined "greater than equals and less than equals" condition.

The EMPLOYEE_TBL table to understand the BETWEEN clause has the following records:

Mysql> SELECT * from EMPLOYEE_TBL;
+------+------+------------+--------------------+
| id |  name | work_date | daily_typing_pages
| +------+------+------------+--------------------+
|  1 | John | 2007-01-24 |        The |
|  2 | Ram | 2007-05-27 |        The |
|  3 | Jack | 2007-05-06 |        170 |
|  3 | Jack | 2007-04-06 |        |
|  4 | Jill | 2007-04-06 |        The |
|  5 | Zara | 2007-06-06 |        A |
|  5 | Zara | 2007-02-06 |        |
+------+------+------------+--------------------+
7 rows in Set (0.00 sec)

Now, suppose you want to get a record condition daily_typing_pages more than 170, equal to and less than 300 according to the table above. This can be >= and <= using the following conditions

Mysql>select * from Employee_tbl 
  ->where daily_typing_pages >= 170 and
  ->daily_typing_pages <= ;
+------+------+------------+--------------------+
| id |  name | work_date | daily_typing_pages
| +------+------+------------+--------------------+
|  1 | John | 2007-01-24 |        The |
|  2 | Ram | 2007-05-27 |        The |
|  3 | Jack | 2007-05-06 |        170 |
|  4 | Jill | 2007-04-06 |        The |
|  5 | Zara | 2007-06-06 |        |
+------+------+------------+--------------------+
5 rows in Set (0.03 sec)

The same can be accomplished using the between clause as follows:

Mysql> SELECT * from Employee_tbl 
  -> WHERE daily_typing_pages BETWEEN 170 and; 
+------+------+------------+--------------------+
| id |  name | work_date | daily_typing_pages
| +------+------+------------+--------------------+
|  1 | John | 2007-01-24 |        The |
|  2 | Ram | 2007-05-27 |        The |
|  3 | Jack | 2007-05-06 |        170 |
|  4 | Jill | 2007-04-06 |        The |
|  5 | Zara | 2007-06-06 |        |
+------+------+------------+--------------------+
5 rows in Set (0.03 sec)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.