Search string by exact word in Mysql

后端 未结 8 1259
广开言路
广开言路 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:25

    You can use REGEXP and the [[:<:]] and [[:>:]] word boundary markers:

    SELECT
        *
    FROM
        `table`
    WHERE
        company REGEXP '[[:<:]]Demo[[:>:]]';
    

    Another Solution

    SELECT
        *
    FROM
        `table`
    WHERE
        company REGEXP '(^|[[:space:]])Demo([[:space:]]|$)';
    

    SQL Fiddle Demo

提交回复
热议问题