MYSQL mode Query

Source: Internet
Author: User

Suppose MYSQL has a database, and it has a table pet.
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Name | varchar (20) | YES | NULL |
| Owner | varchar (20) | YES | NULL |
| Species | varchar (20) | YES | p NULL |
| Sex | char (1) | YES | NULL |
| Birth | date | YES | NULL |
| Death | date | YES | NULL |
+ --------- + ------------- + ------ + ----- + --------- + ------- +

One is standard matching of SQL.
Query all records whose names start with B:
Select * from pet where name like 'B % ';
Here '%' is similar to '*' in windows, while '_' is similar '? '.

The other is regular expression matching.
For example, you can query the pet.
Select * from pet where owner regexp '^ Chen ';
Or select * from pet where owner rlike '^ Chen ';
Find out if the pet name is exactly 4 characters long.
Select * from where name rlike '^ {4} $ ';
Or select * from where name rlike '^... $ ';
These are similar to regular expressions.

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.