SQL SELECT LIKE (Insensitive casing)

MysqlSqlSql LikeCase Insensitive

Mysql Problem Overview


I am trying to execute the sql query:

select * from table where column like '%value%';

But the data is saved as 'Value' ( V is capital ).

When I execute this query i don't get any rows. How do i make the call such that, it looks for 'value' irrespective of the casing of the characters ?

Mysql Solutions


Solution 1 - Mysql

use LOWER Function in both (column and search word(s)). Doing it so, you assure that the even if in the query is something like %VaLuE%, it wont matter

select qt.*
from query_table qt
where LOWER(column_name) LIKE LOWER('%vAlUe%');

Solution 2 - Mysql

If you want this column be case insensitive :

ALTER TABLE `schema`.`table` 
CHANGE COLUMN `column` `column` TEXT CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';

Thus, you don't have to change your query.

And the MySQL engine will process your query quicker than using lower() function or any other tricks.

And I'm not sure that using lower function will be a good solution for index searching performance.

Solution 3 - Mysql

Either use a case-insensitive collation on your table, or force the values to be lower case, e.g.

WHERE lower(column) LIKE lower('%value%');

Solution 4 - Mysql

Use the lower() function:

select t.*
from table t
where lower(column) like '%value%';

Solution 5 - Mysql

Try using a case insensitive collation

select * from table
where column like '%value%' collate utf8_general_ci

Solution 6 - Mysql

you should use either lower or upper function to ignore the case while you are searching for some field using like.

select * from student where upper(sname) like 'S%';

OR

select * from student where lower(sname) like 'S%';

Solution 7 - Mysql

If you are using PostgreSQL, a simpler solution is to use insensitive like (ILIKE):

SELECT * FROM table WHERE column ILIKE '%value%'

Solution 8 - Mysql

I know this is a very old question, but I'm posting this for posterity:
Non-binary string comparisons (including LIKE) are case-insensitive by default in MySql: https://dev.mysql.com/doc/refman/en/case-sensitivity.html

Solution 9 - Mysql

This will eventually do the same thing. The ILIKE works, irrespective of the casing nature

SELECT * FROM table WHERE column_name ILIKE "%value%"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2583714View Question on Stackoverflow
Solution 1 - MysqlJGutierrezCView Answer on Stackoverflow
Solution 2 - MysqlkmasView Answer on Stackoverflow
Solution 3 - MysqlMarc BView Answer on Stackoverflow
Solution 4 - MysqlGordon LinoffView Answer on Stackoverflow
Solution 5 - Mysqljuergen dView Answer on Stackoverflow
Solution 6 - MysqlGovindu SurlaView Answer on Stackoverflow
Solution 7 - MysqlAlter LagosView Answer on Stackoverflow
Solution 8 - MysqlMarko BonaciView Answer on Stackoverflow
Solution 9 - Mysqlkelvin93View Answer on Stackoverflow