MySQL's Fuzzy search

Source: Internet
Author: User

1. Fuzzy Search

The first time I immediately thought of the keyword like

1.1. The field to be queried contains a specific character, but is not determined by its location , using two% package up

SELECT * from phone where provider like '%Apple%'

Can match 'AppleXXX ', ' xxapplexx ', ' ABCDEFGApple'

1.2. Be able to determine the end of the field to be checked , as follows:

SELECT * from Student where name is like '% Cong ';

Can match to ' Huang Cong ', ' Cong ', ' xxx cong ' ( must be the end of the Cong )

1.3. determine the beginning ,

SELECT * from Student where name is like ' yellow ';

Can be matched to ' Huang Cong ', ' Huang XXXXX ' (Must be yellow-beginning)

It can be observed that the use of the keyword like must be used in conjunction with percent percent, for the above three cases

First, be able to determine the beginning: After the determination of the partial semicolon, like ' Tom%'

Second, to be able to determine the end of, in the determination of the part before the percent semicolon, like '%Tom '

Third, only know contains, but can not determine the specific location, like '%Tom%'

Special Note : As the efficiency of like is usually very low, so try to use less, if you have to use, it is best to meet the third case, that is, to determine the initial content,

Because this is able to use the index , and the other two can not use the index, will scan the whole table, so very slow.

2. Using MySQL built-in functions

Please refer to:MySQL uses built-in functions for fuzzy search (locate (), etc.)

3. Full-text indexing using MySQL

MySQL's Fuzzy search

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.