0

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?

1

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

showing error- ERROR 1253 (42000): COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1' for the 1st command. 2nd one runs fine.
If your client charset is set to latin1 you can use latin1_bin, which is the binary collation that corresponds to the latin1 charset.
thanx for navigating me with proper concept.
1

By default, MySQL is case-insensitive. Either change column collation, or use COLLATE keyword, like:

SELECT 'abc' COLLATE 'utf8_bin' = 'abc' COLLATE 'utf8_bin'

1 Comment

It's a character set dependent answer. In my system its throwing an error- ERROR 1253 (42000): COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1'
0

Command1

select BINARY 'aBc'='Abc';

O/P

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

Command2

select BINARY 'aBc'= 'aBc';

O/P

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.