MySQL Search Query on two different fields

后端 未结 4 1120
清歌不尽
清歌不尽 2021-02-10 03:30

I need to search on two fields using LIKE function and should match also in reverse order. My table uses InnoDB which dont have Full text search.

Consider the following

4条回答
  •  孤城傲影
    2021-02-10 03:51

    When you CONCAT() two columns the LIKE become case sensitive. So this should find you results but isn't optimal for performance:

    SELECT CONCAT(first_name, ' ', last_name) AS fullname FROM users 
    WHERE LOWER(CONCAT(first_name, ' ', last_name)) LIKE LOWER('%doe%');
    

    That's getting MySQL to do work on each row though.

提交回复
热议问题