SQL SELECT LIKE (Insensitive casing)

后端 未结 9 1782
野性不改
野性不改 2021-02-02 05:32

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 ).

相关标签:
9条回答
  • 2021-02-02 06:29

    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.

    0 讨论(0)
  • 2021-02-02 06:34

    Try using a case insensitive collation

    select * from table
    where column like '%value%' collate utf8_general_ci
    
    0 讨论(0)
  • 2021-02-02 06:35

    Use the lower() function:

    select t.*
    from table t
    where lower(column) like '%value%';
    
    0 讨论(0)
提交回复
热议问题