October 2002
Intermediate to advanced
1024 pages
27h 26m
English
A string comparison is case sensitive when you don’t want it to be, or vice versa.
Alter the case sensitivity of the strings.
The examples in previous sections were performed without regard to lettercase. But sometimes you need to make sure a string operation is case sensitive that would not otherwise be, or vice versa. This section describes how to do that for ordinary comparisons. Recipe 4.11 covers case sensitivity in pattern-matching operations.
String comparisons in MySQL are not case sensitive by default:
mysql> SELECT name, name = 'lead', name = 'LEAD' FROM metal;
+----------+---------------+---------------+
| name | name = 'lead' | name = 'LEAD' |
+----------+---------------+---------------+
| copper | 0 | 0 |
| gold | 0 | 0 |
| iron | 0 | 0 |
| lead | 1 | 1 |
| mercury | 0 | 0 |
| platinum | 0 | 0 |
| silver | 0 | 0 |
| tin | 0 | 0 |
+----------+---------------+---------------+The lack of case sensitivity also applies to relative ordering comparisons:
mysql> SELECT name, name < 'lead', name < 'LEAD' FROM metal;
+----------+---------------+---------------+
| name | name < 'lead' | name < 'LEAD' |
+----------+---------------+---------------+
| copper | 1 | 1 |
| gold | 1 | 1 |
| iron | 1 | 1 |
| lead | 0 | 0 |
| mercury | 0 | 0 |
| platinum | 0 | 0 |
| silver | 0 | 0 |
| tin | 0 | 0 |
+----------+---------------+---------------+If you’re familiar with the ASCII collating order, you know that lowercase ...
Read now
Unlock full access