MySQL Regular query fuzzy query

Source: Internet
Author: User

--============== Regular Query ================/*SQL defaults to the case-insensitive regular pattern using the regexp and not regexp operators (or rlike and not rlike, which are synonyms).      The regular value of the field contains the contents of the regular.  Matches any single character that represents any one-word [...] Matches a string containing a single character within square brackets, [0-9] matches a number between 0 and 9 * matches 0 or more characters in front of it {n} matches n characters in front of it if you want the case to match on the write. [AA] Match case a,[a-za-z] matches any A-Z single letter of the case. But the default is not case-sensitive [b] can also match the string on the B also to match the character at the beginning of the field, using ^, at the end of the field with $ if it is a Chinese character, you may need to pay attention to when using. */--field name only four values, NAME_AA, Name_ab, name_ everyone, name_% good _SELECT *  from' test_t 'WHERENAME REGEXP'[A-z]';--A string containing A to Z character that can match to Name_aa and Name_ab and name_ everyone and name_% good _SELECT *  from' test_t 'WHERENAME REGEXP'^n.....b$';--A string of 7 characters long ending with n beginning with B, can match to Name_abSELECT *  from' test_t 'WHERENAME Rlike'd*';--A string containing 0 or more D that matches all the values of the field, since * 0 of the preceding characters also matchSELECT *  from' test_t 'WHERENAME Rlike'b{1}$';--End is a B, can match to Name_ab--============== fuzzy Query ================--wildcard characters in the like statement for MySQL: percent, underline, and escape--% represents any or more arbitrary characters. Can match any type and length of characters. SELECT *  from' test_t 'WHERENAME like '%me_ab';--Query Result Name_ab--If you need to find a record in name that has both B and a, use the and conditionSELECT *  from' test_t 'WHERENAME like '%b%'  andNAME like '%a%';--If you use SELECT * from ' test_t ' WHERE NAME like '%b%a% '; Name_ab is not found--_ represents any single character. Matches a single arbitrary character, which is commonly used to restrict the expression's character-length statement (which can represent a Chinese word character)SELECT *  from' test_t 'WHERENAME like '_______';--can query to Name_aa and Name_ab and name_ 7 character length of a value--If you want to check the character% or _ use escape, the escape character after the% or _ is not as a wildcard, note that there is no escape character before the% and _ still play the role of wildcardsSELECT *  from' test_t 'WHERENAME like 'name_/%% Good/_' ESCAPE '/';--Query Results name_% Good _

MySQL Regular query fuzzy query

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.