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

Detailed process of installing Jenkins-2.249.3-1.1 with Docker

Table of contents 1. Install Docker 2. Pull the J...

Example of how to identify the user using a linux Bash script

It is often necessary to run commands with sudo i...

Detailed description of shallow copy and deep copy in js

Table of contents 1. js memory 2. Assignment 3. S...

Detailed explanation of three relationship examples of MySQL foreign keys

This article uses examples to describe the three ...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

Docker deploys Mysql, .Net6, Sqlserver and other containers

Table of contents Install Docker on CentOS 8 1. U...

How to use IDEA to configure tomcat and create JSP files

Before using idea to write JSP files, you need to...

Summary of methods to check whether the port is open in Linux

Method 1: Use lsof command We can use the lsof co...

Do you know how many connections a Linux server can handle?

Preface First, let's see how to identify a TC...

A mobile adaptive web page effect solves the problem of small display page

For work needs, I need to make a mobile phone adap...