Search string by exact word in Mysql

后端 未结 8 1174
广开言路
广开言路 2021-01-18 07:11

I have a system that searches for company. I want that when a user searches for \"Demo\", all records that have \"Demo\" will be returned, like \"The Demo\", \"Demo Inc.\",

8条回答
  •  鱼传尺愫
    2021-01-18 07:29

    The best solution is create a fulltext index:

    create fulltext index `i_company` on `table`(`company`);
    

    Then you can search as:

    select * from `table` where match(company) against ('Demo');
    

    Read more about mysql full text search.

    Depending on your MySQL version, Full text index is available for MyISAM in version 5.5 or less, and is available for InnoDB since 5.6.

提交回复
热议问题