Home >Database >Mysql Tutorial >How Can I Perform a Case-Insensitive LIKE Search in MySQL?
Performing Case-Insensitive LIKE Searches in MySQL
MySQL's LIKE
operator is inherently case-sensitive. This means a search for 'elm' won't find 'Elm' or 'ELM'. To create a case-insensitive search, utilize the LOWER()
function.
For instance, the following query:
<code class="language-sql">SELECT * FROM trees WHERE trees.title LIKE '%elm%';</code>
will only return rows where trees.title
contains "elm" in that exact case.
To make the search case-insensitive, modify the query like this:
<code class="language-sql">SELECT * FROM trees WHERE LOWER(trees.title) LIKE '%elm%';</code>
This revised query converts the trees.title
column to lowercase before comparing it to '%elm%', thus ensuring that the search is not affected by capitalization. This method effectively performs a case-insensitive wildcard search, returning all rows where the lowercase version of the title includes "elm".
The above is the detailed content of How Can I Perform a Case-Insensitive LIKE Search in MySQL?. For more information, please follow other related articles on the PHP Chinese website!