Detailed explanation of the problem of matching even when there is a space at the end of the string in the Mysql query condition

Detailed explanation of the problem of matching even when there is a space at the end of the string in the Mysql query condition

1. Table structure

TABLE person

id name
1 you
2 You (a space)
3 You (two spaces)

2. Query and Results

select * from person where `name` = ?

regardless? = "you + a few spaces", all three results will be retrieved.

3. Reasons

MySQL's collation rules are PADSPACE, which ignores trailing spaces.

It is aimed at text data types such as varchar char text...

This is SQL standardized behavior. No settings are required and cannot be changed.

4. What if you want to make an accurate query?

Method 1: like

select * from person where `name` like ?

Method 2: BINARY

select * from person where `name` = BINARY ?

BINARY is not a function, but a type conversion operator. It is used to force the string behind it to be a binary string, which can be understood as an exact match.

The above are all the relevant knowledge points introduced this time. If you have any additions, please contact the editor of 123WORDPRESS.COM.

You may also be interested in:
  • MySQL retrieves data based on the JSON field content as a query condition (including JSON arrays)
  • The difference and reasons between the MySQL query conditions not in and in
  • Detailed explanation of common usage of MySQL query conditions
  • Will the index be used in the MySQL query condition?
  • Analysis of the difference between placing on and where in MySQL query conditions
  • MySQL explains how to optimize query conditions

<<:  JavaScript using Ckeditor + Ckfinder file upload case detailed explanation

>>:  Using jQuery to implement the carousel effect

Recommend

Linux CentOS MySQL database installation and configuration tutorial

Notes on installing MySQL database, share with ev...

How to change the domestic image source for Docker

Configure the accelerator for the Docker daemon S...

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...

Detailed tutorial on installing MySQL database in Linux environment

1. Install the database 1) yum -y install mysql-s...

How to add fields and comments to a table in sql

1. Add fields: alter table table name ADD field n...

Vue realizes the function of book shopping cart

This article example shares the specific code of ...

Vue realizes click flip effect

Use vue to simply implement a click flip effect f...

MySQL time types and modes details

Table of contents 1. MySQL time type 2. Check the...

Detailed explanation of overflow-scrolling to solve scrolling lag problem

Preface If you use the overflow: scroll attribute...

JavaScript Basics: Immediate Execution Function

Table of contents Immediately execute function fo...

How to connect to a remote docker server with a certificate

Table of contents 1. Use scripts to encrypt TLS f...

Web page HTML code explanation: ordered list and unordered list

In this section, we will learn about list element...

WeChat applet to determine whether the mobile phone number is legal example code

Table of contents Scenario Effect Code Summarize ...

Share 8 MySQL pitfalls that you have to mention

MySQL is easy to install, fast and has rich funct...