Mysql uses instr for fuzzy query, instr fuzzy query

Source: Internet
Author: User

Mysql uses instr for fuzzy query, instr fuzzy query

Using the internal function instr in mysql can replace the traditional like query method, and the query speed is faster.

Instr function. The first parameter is a field, and the second parameter is the string to be queried. The position of the returned string is 1. If it is not found, it is 0.

For example, to query the name of a field with "Jun", the traditional method is:

Select name from user table where name like '% Jun % ';

Using instr:

Select name from user table where instr ('name', 'june ');

Or:

Select name from user table where instr ('name', 'june')> 0;

Table

Field: Name

Zhang San
Wang Wu

Table B

Field: title

Information Released
Information II Wang Wu released
Information 3-3 release

Ranking list, sorted by the number of entries in table A's name like % 'name' % matching the title of table B,

Select name, count (B. title) from a inner join B on instr (B. title, a. Name)> 0 group by name order by count (B. title)

Summary

The above is all about how to use instr for fuzzy search in mysql. I hope it will be helpful to you. If you are interested, you can continue to refer to this site: explain the meaning of N and m in the MySQL Data Type DECIMAL (N, M), and analyze the differences between FIND_IN_SET () and IN, if you have any questions, you can leave a message at any time. The editor will reply to you in a timely manner. Thank you for your support!

Related Article

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.