Home > Database > Mysql Tutorial > How Does MySQL Handle Case Sensitivity in SELECT Queries, and How Can I Override It?

How Does MySQL Handle Case Sensitivity in SELECT Queries, and How Can I Override It?

DDD
Release: 2024-12-11 16:39:10
Original
197 people have browsed it

How Does MySQL Handle Case Sensitivity in SELECT Queries, and How Can I Override It?

MySQL SELECT Query Case Sensitivity

By default, MySQL SELECT queries are case insensitive. This means that the query SELECT * FROM table` WHERE `Value` = "iaresavage" will return results even if the value of Value` column is actually 'IAreSavage'.

Overriding Case Sensitivity

However, you can override this default behavior and perform case-sensitive comparisons using the binary operator. To do this, modify your query as follows:

SELECT * FROM `table` WHERE BINARY `Value` = "iaresavage"
Copy after login
Copy after login

Now, the query will only return results if the value of the Value column exactly matches the specified string, regardless of case.

Example

Consider the following table:

Value
iaresavage
IAreSavage

If you execute the following query:

SELECT * FROM `table` WHERE `Value` = "iaresavage"
Copy after login

It will return both rows because the query is case insensitive.

However, if you execute the following query:

SELECT * FROM `table` WHERE BINARY `Value` = "iaresavage"
Copy after login
Copy after login

It will only return the first row because the case-sensitive comparison eliminates the second row.

The above is the detailed content of How Does MySQL Handle Case Sensitivity in SELECT Queries, and How Can I Override It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template