MySQL multi-item fuzzy query

Source: Internet
Author: User

Recently, there is a need to find qualifying data based on the keywords in the search box.

If it is a single condition, it is actually a normal SELECT statement.

But the requirement is this keyword, to be in id,desc,step and so on multiple fields fuzzy lookup.

Then one of the most intuitive ideas must be:

Select *  from where  like  % Key % or 'desclike%key%or like % Key %

For a record, the ID, DESC, step Three are judged that the character does not match the key.

Cons: The requirement is only three records, if it is multiple records, it will be very slow, and modify the statement is also very complex.

A better approach is to combine the fields that need fuzzy queries with concat to make a whole string, and then use like to match.

SELECT *  from WHERE  CONCAT ('desclike%key%

That's what I did in the project, and the mentor thought it was no big deal:

Do you have any better way, you can also exchange a bit of Kazakhstan.

MySQL multi-item 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.