Introduction to fuzzy query method using instr in mysql

Introduction to fuzzy query method using instr in mysql

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

The instr function takes the field as its first argument and the string to be queried as its second argument. It returns the position of the string. The first one is 1, and if it is not found, it is 0.

For example, to query names with "军" in the field name, the traditional method is:

select name from user table where name like `%军%';

Using the instr method:

select name from user table where instr('name','军');

or:

select name from user table where instr('name','军')>0;

Table A

Field: Name

Zhang San
Wang Wu

Table B

Field: title

Information is published in three parts
Information released by Wang Wu
Information is released three times

Ranking list, sort by the number of entries where the name like %'name'% in table A matches the title in 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)

Summarize

The above is all the content of this article about the use of instr for fuzzy query method in MySQL. I hope it will be helpful to everyone. Interested friends can continue to refer to this site: Detailed explanation of the meanings of N and M in the MySQL data type DECIMAL(N,M), a brief analysis of the differences between FIND_IN_SET() and IN in MySQL, etc. If you have any questions, you can leave a message at any time and the editor will reply to you in time. Thank you friends for supporting this site!

You may also be interested in:
  • PHP+MySQL to implement fuzzy query employee information function example
  • PHP+MySQL uses mysql_num_rows to implement fuzzy query book information function
  • Detailed introduction to the use of MySQL fuzzy query LIKE and REGEXP
  • A brief discussion on wildcard escape in MySQL fuzzy query
  • What to do if Mybatis cannot retrieve results when entering Chinese characters using MySQL fuzzy query
  • MySQL fuzzy query statement collection

<<:  Linux CentOS6.9 installation graphic tutorial under VMware

>>:  How to install Maven automatically in Linux continuous integration

Recommend

Modification of time zone problem of MySQL container in Docker

Preface When Ahhang was developing the Springboot...

How to modify create-react-app's configuration without using eject

1. Why is eject not recommended? 1. What changes ...

Detailed explanation on how to deploy H5 games to nginx server

On the road to self-learning game development, th...

A pitfall and solution of using fileReader

Table of contents A pitfall about fileReader File...

How to configure jdk environment under Linux

1. Go to the official website to download the jdk...

How to obtain and use time in Linux system

There are two types of Linux system time. (1) Cal...

MySQL foreign key constraint (FOREIGN KEY) case explanation

MySQL foreign key constraint (FOREIGN KEY) is a s...

JavaScript setinterval delay one second solution

When using setinterval, it is found that it will ...

Nginx reverse proxy configuration removes prefix

When using nginx as a reverse proxy, you can simp...

Using zabbix to monitor the ogg process (Windows platform)

This article introduces how to monitor the ogg pr...

JavaScript to achieve click image flip effect

I was recently working on a project about face co...

What to do if the online MySQL auto-increment ID is exhausted

Table of contents Table definition auto-increment...

Pitfall notes of vuex and pinia in vue3

Table of contents introduce Installation and Usag...

JavaScript file loading and blocking issues: performance optimization case study

Let me start with a question: When writing an HTM...