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 explanation of the role of explain in MySQL

1. MYSQL index Index: A data structure that helps...

Practical explanation of editing files, saving and exiting in linux

How to save and exit after editing a file in Linu...

Sample code for implementing PC resolution adaptation in Vue

Table of contents plan Install Dependencies Intro...

Summary of some points to note when registering Tomcat as a service

Here are some points to note when registering Tom...

Six border transition effects implemented by CSS3

Six effectsImplementation Code html <h1>CSS...

React new version life cycle hook function and usage detailed explanation

Compared with the old life cycle Three hooks are ...

Conflict resolution when marquee and flash coexist in a page

The main symptom of the conflict is that the FLASH...

A brief discussion on whether too many MySQL data queries will cause OOM

Table of contents Impact of full table scan on th...

React Hooks Usage Examples

Table of contents A simple component example More...

Basic usage and pitfalls of JavaScript array sort() method

Preface In daily code development, there are many...

The perfect solution for Vue routing fallback (vue-route-manager)

Table of contents Routing Manager background gett...

An article teaches you how to implement a recipe system with React

Table of contents 1. Recipe Collection 1.1 Projec...

How to lock a virtual console session on Linux

When you are working on a shared system, you prob...

How to implement nested if method in nginx

Nginx does not support nested if statements, nor ...