1

I have a Login table in MySql database . . In table there is a column by cname and one of the value is 'Raghu'. My question is when i write the query as

Select *from Login where cname='raghu';

Then it is retrieving the record which contains 'Raghu' . I want it to retrieve according to case . How can I retrieve with case sensitively, values in the data of tables.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Raghavendra M
  • 199
  • 2
  • 3
  • 8
  • Here is another link I found [MySQL case insensitive select](http://stackoverflow.com/questions/3936967/mysql-case-insensitive-select) – Grijesh Chauhan Dec 01 '13 at 05:09

3 Answers3

1

Use: 10.1.7.7. The BINARY Operator

The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character.

Select * from Login where  binary cname='raghu';
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
  • Thank u , but is there any default option for this , because in project i have to use binary for all queries, it is little tedious . – Raghavendra M Dec 01 '13 at 05:12
  • @RaghavendraM actually this is good question. But I don't think there is any flag by using that you can make query case sensitive. At-least I don't know. – Grijesh Chauhan Dec 01 '13 at 05:16
  • k . . and do you know what this line will do in query, /*!40101 SET character_set_client = utf8 */; this line was used in creating table – Raghavendra M Dec 01 '13 at 05:19
  • @RaghavendraM In Mysql by default collation is case-insensitive - `H` is equivalent to `h` and Using BINARY in the WHERE clause forces a match on the binary collation, which in English means that it matches actual characters by their character code. Read the link I given in my answer. – Grijesh Chauhan Dec 01 '13 at 05:21
0
SELECT * from Login WHERE STRCMP(cname,'Raghu')=0;
dlock
  • 9,447
  • 9
  • 47
  • 67
0

Can you try this, you can use LOWER FUNCTION in either column name LOWER('cname') or in value LOWER('raghu');

Select *from Login where LOWER(`cname`) = 'raghu';
Krish R
  • 22,583
  • 7
  • 50
  • 59