- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement case sensitivity in MySQL SELECT statements
SELECT is by default case-insensitive. For case-sensitive implementation, the BINARY operator is used. Following is the syntax :
select *from yourTableName where BINARY yourColumnName=yourValue;
Let us first create a table −
mysql> create table DemoTable ( Name varchar(40) ); Query OK, 0 rows affected (0.74 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('CHRIS'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('CHris'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Name | +-------+ | Chris | | CHRIS | | chris | | CHris | +-------+ 4 rows in set (0.00 sec)
Following is the query for case-sensitive select −
mysql> select *from DemoTable where BINARY Name='Chris';
This will produce the following output −
+-------+ | Name | +-------+ | Chris | +-------+ 1 row in set (0.04 sec)
Advertisements