Count occurrences of a word in a row in MySQL

后端 未结 9 1015
野趣味
野趣味 2020-12-19 08:41

I\'m making a search function for my website, which finds relevant results from a database. I\'m looking for a way to count occurrences of a word, but I need to ensure that

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 09:27

    Something like this should work:

    select count(*) from table where fieldname REGEXP '[[:<:]]word[[:>:]]';

    The gory details are in the MySQL manual, section 11.4.2.

提交回复
热议问题