Explanation of the concept and usage of Like in MySQL

Explanation of the concept and usage of Like in MySQL

Like means "like" in Chinese, but when applied to MySQL database, Like is a statement used for fuzzy query, mainly for character fields, to retrieve the corresponding substring in a character field column. This article introduces the Like statement in MySQL.

1. What does Like mean?

1. Like is considered a predicate in MySQL, and its application is similar to the usage of symbols such as is, =, >, and <.

2. In the SQL structured query language, the like statement plays a vital role.

3. In a sense, Like can be seen as a streamlined regular expression function.

2. Like function

The syntax of the like statement is

select * from table name where field name like corresponding value (substring)

Function: Mainly for character fields, to search for corresponding substrings in a character field column.

3. Like Support Types

Like mainly supports two wildcard characters, "_" and "%".

1. "_" represents matching one arbitrary character and is often used as a placeholder;

2. "%" means matching 0 or more arbitrary characters.

4. Two usage scenarios of Like

1. The field values ​​stored in the database are more accurate, and the parameters are fuzzy values ​​(this is usually the case);

2. The field values ​​stored in the database are fuzzy values, and the parameters are more precise values.

Knowledge point expansion:

In MySQL, the SQL mode is case-insensitive by default. Some examples are shown below. Note that when you use SQL mode, you cannot use = or ! =; use the LIKE or NOT LIKE comparison operator.

SELECT field FROM table WHERE a field Like condition

Regarding conditions, SQL provides four matching modes:

%: represents any one or more characters. Matches characters of any type and length.

for example

SELECT * FROM [user] WHERE u_name LIKE '%三%'

This is the end of this article about the concept and usage of Like in MySQL. For more information about what Like means in MySQL, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation of fuzzy query like%% in MySQL
  • Detailed analysis of MySQL optimization of like and = performance
  • Tutorial on using the LIKE clause in MySQL
  • Table replication in MySQL: create table like and create table as select
  • Summary of MySQL fuzzy query like and regexp

<<:  Detailed explanation of several ways to remove the gap between inline-block elements in CSS

>>:  Vue computed properties

Recommend

How to reset the root password of Mysql in Windows if you forget it

My machine environment: Windows 2008 R2 MySQL 5.6...

Mysql optimization tool (recommended)

Preface While browsing GitHub today, I found this...

Use of marker tags in CSS list model

This article mainly introduces the ::master pseud...

Detailed explanation of Cgroup, the core principle of Docker

The powerful tool cgroup in the kernel can not on...

MySQL uses covering index to avoid table return and optimize query

Preface Before talking about covering index, we m...

Introduction to the use of em in elastic layout in CSS3: How many pixels is 1em?

I have been using CSS for a long time, but I have...

A brief discussion on Flink's fault-tolerant mechanism: job execution and daemon

Table of contents 1. Job Execution Fault Toleranc...

A brief discussion on the design and optimization of MySQL tree structure tables

Preface In many management and office systems, tr...

MySQL calculates the number of days, months, and years between two dates

The MySQL built-in date function TIMESTAMPDIFF ca...

mysql is not an internal command error solution

The error "mysql is not an internal command&...

How to modify the contents of an existing Docker container

1. Docker ps lists containers 2. Docker cp copies...

An example of using Lvs+Nginx cluster to build a high-concurrency architecture

Table of contents 1. Lvs Introduction 2. Lvs load...

Detailed explanation of React event binding

1. What is In react applications, event names are...