
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How do you force MySQL LIKE to be case sensitive?
To force MySQL LIKE to be case sensitive with the help of LIKE BINARY, the following is the syntax −
select yourColumnName like binary 'anyStringValue' from yourTableName;
To understand the above concept, let us create a table. The following is the query to create a table −
mysql> create table LikeBinaryDemo −> ( −> Name varchar(200) −> ); Query OK, 0 rows affected (0.58 sec)
Now you can insert records with small letters to force the MySQL LIKE to be case sensitive −
mysql> insert into LikeBinaryDemo values('john'); Query OK, 1 row affected (0.12 sec)
Display the records in the table. The query is as follows −
mysql> select *from LikeBinaryDemo;
The following is the output −
+------+ | Name | +------+ | john | +------+ 1 row in set (0.00 sec)
Case 1 − Using BINARY
Now you can use LIKE BINARY to force the MySQL Like to be case sensitive.
LIKE BINARY. In this case, we will get value 0 when we compare ‘john’ with ‘JOHN’. The query is as follows −
mysql> select Name like binary 'JOHN' from LikeBinaryDemo;
The following is the output −
+-------------------------+ | Name like binary 'JOHN' | +-------------------------+ | 0 | +-------------------------+ 1 row in set (0.00 sec)
Case 2 − Without using BINARY
Now let us see what will happen when we are not using BINARY. The query is as follows −
mysql> select Name like 'JOHN' from LikeBinaryDemo;
The following is the output −
+------------------+ | Name like 'JOHN' | +------------------+ | 1 | +------------------+ 1 row in set (0.00 sec)
You can use LIKE BINARY to force MySQL to be case sensitive.
- Related Articles
- How to do case-sensitive string comparison in JavaScript?
- How to achieve case sensitive uniqueness and case insensitive search in MySQL?
- How do you OR two MySQL LIKE statements?
- How MySQL can perform case-sensitive string comparison?
- How to make SQL case sensitive string comparison in MySQL?
- Are MySQL database and table names case-sensitive?
- Convert the column to a case-sensitive collation in MySQL?
- What kind of string comparison, case-sensitive or not, can be performed by MySQL?
- Is Python case-sensitive or case-insensitive?
- Case-sensitive sort in JavaScript
- Are Gmail Addresses Case Sensitive
- How to compare two strings without case sensitive in Java
- MySQL select for exact case sensitive match with hyphen in records
- How do I force the column alias to be of specific data type in MySQL?
- Is JavaScript a case sensitive language?
