Reputation: 7019
Consider the following sql command run in MySQL command prompt-
select 'aBc'='Abc';
O/P
+-------------+
| 'aBc'='Abc' |
+-------------+
| 1 |
+-------------+
I expected the result to show '0' in place of '1'.
How can I differentiate between two strings if they are not in the same case?
Upvotes: 0
Views: 263
Reputation: 7019
select BINARY 'aBc'='Abc';
+---------------------+
| BINARY 'aBc'= 'Abc' |
+---------------------+
| 0 |
+---------------------+
select BINARY 'aBc'= 'aBc';
+---------------------+
| BINARY 'aBc'= 'aBc' |
+---------------------+
| 1 |
+---------------------+
Upvotes: 0
Reputation: 9822
By default, MySQL is case-insensitive.
Either change column collation, or use COLLATE
keyword, like:
SELECT 'abc' COLLATE 'utf8_bin' = 'abc' COLLATE 'utf8_bin'
Upvotes: 1
Reputation: 111269
You can use a binary collation. For example:
select 'aBc'='Abc' collate utf8_bin;
Or you can transform one of the strings into a binary type:
select binary('aBc')=binary('Abc');
For the differences between these two, see The _bin and binary Collations in the MySQL documentation.
Upvotes: 1