How to use LIKE clause to do Case-Insensitive Search in a Column In MySQL

The LIKE clause and wildcards in MySQL are powerful tools used in the WHERE clause of a SELECT, UPDATE, or DELETE statement to filter results. It allows you to search for a specified pattern within a column.

Example:

SELECT * FROM Users WHERE name LIKE 'john';

This query will return all customers whose name is “john”. Since it is a case-insensitive search, the query returns multiple rows.

| name |
|------|
| John |
| john |
| joHn |
| JOHN |

How to do Case Sensitive and Case Insensitive Search in a Column in MySQL

LIKE Clause is used to perform case-insensitive searches in a column in MySQL and the COLLATE clause is used to perform case-sensitive searches in a column in MySQL.

Learning both these techniques is important to understand search operations in MySQL. Case sensitivity can affect search queries in MySQL so knowing when to perform a specific type of search becomes very important. This article explains how to search with the LIKE operator and COLLATE() clause with examples.

Similar Reads

Demo MySQL Database

Let’s create a demo MySQL table that will be used for examples in this tutorial....

COLLATION

In MySQL, a collation determines how string comparison is done. It’s a set of rules that define how characters in a character set are compared and sorted....

Using LIKE clause to do Case-Insensitive Search in a Column

The LIKE clause and wildcards in MySQL are powerful tools used in the WHERE clause of a SELECT, UPDATE, or DELETE statement to filter results. It allows you to search for a specified pattern within a column....

Using COLLATE() Clause to do Case-sensitive Search in a Column

COLLATE clause is used to perform a case-sensitive search operation in a column in MySQL. The COLLATE clause allows users to specify the collation or the set of rules for comparing strings in SQL....

Conclusion

MySQL provides powerful tools for string comparison and pattern matching in SQL queries. The LIKE operator, used in conjunction with wildcards, allows for flexible pattern matching within a column. By default, MySQL uses a case-insensitive collation for string comparisons, treating ‘A’ and ‘a’ as the same. This is useful for most general use-cases....

Contact Us