Like Case Sensitive in MySQL

后端 未结 8 2352
离开以前
离开以前 2020-11-29 06:38

I have a MySQL query:

SELECT concat_ws(title,description) as concatenated HAVING concatenated LIKE \'%SearchTerm%\';

And my table is encode

相关标签:
8条回答
  • 2020-11-29 07:13

    Just for completion, in case it helps:

    As stated on https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html, for default character sets, nonbinary string comparisons are case insensitive by default.

    Therefore, an easy way to perform case-insensitive comparisons is to cast the field to CHAR, VARCHAR or TEXT type.

    Here is an example with a check against a single field:

    SELECT * FROM table1 WHERE CAST(`field1` AS CHAR) LIKE '%needle%';
    
    0 讨论(0)
  • 2020-11-29 07:14

    In this method, you do not have to select the searched field:

    SELECT table.id 
    FROM table
    WHERE LOWER(table.aTextField) LIKE LOWER('%SearchAnything%')
    
    0 讨论(0)
提交回复
热议问题