SQL SELECT LIKE (Insensitive casing)

风流意气都作罢 提交于 2019-12-02 21:39:20

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%');

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.

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%');

Use the lower() function:

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

Try using a case insensitive collation

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

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

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

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%';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!