MySQL SELECT Queries: Case Sensitivity and Case Insensitivity
MySQL SELECT queries default to case-insensitive behavior, meaning that they do not distinguish between uppercase and lowercase characters. This means that the query you provided:
SELECT * FROM `table` WHERE `Value` = "iaresavage"
will match rows where the Value column contains either "iaresavage" or "IAREsAvagE".
Enforcing Case Sensitivity
If you want your query to be case sensitive, you can use a binary comparison operator, which explicitly specifies that the comparison should be made byte-by-byte:
SELECT * FROM `table` WHERE BINARY `Value` = "IAREsAvagE"
Example
Consider the following table:
CREATE TABLE `table` (`Value` VARCHAR(255)); INSERT INTO `table` VALUES ('iaresavage', 'IAREsAvagE');
If you execute the following query:
SELECT * FROM `table` WHERE `Value` = "iaresavage"
it will return both rows, even though the values are different.
However, if you execute the following query:
SELECT * FROM `table` WHERE BINARY `Value` = "IAREsAvagE"
it will only return the row where the value is exactly "IAREsAvagE".
The above is the detailed content of How Do MySQL SELECT Queries Handle Case Sensitivity, and How Can I Enforce Case-Sensitive Comparisons?. For more information, please follow other related articles on the PHP Chinese website!