Rajesh Paul
Rajesh Paul

Reputation: 7019

Differentiate between two strings with different case in mysql

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

Answers (3)

Rajesh Paul
Rajesh Paul

Reputation: 7019

Command1

select BINARY 'aBc'='Abc';

O/P

+---------------------+
| BINARY 'aBc'= 'Abc' |
+---------------------+
|                   0 |
+---------------------+

Command2

select BINARY 'aBc'= 'aBc';

O/P

+---------------------+
| BINARY 'aBc'= 'aBc' |
+---------------------+
|                   1 |
+---------------------+

Upvotes: 0

Guillaume Poussel
Guillaume Poussel

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

Joni
Joni

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

Related Questions