Count occurrences of a word in a row in MySQL

后端 未结 9 1002
野趣味
野趣味 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:19

    Something like LIKE or REGEXP will not scale (unless it's a leftmost prefix match).

    Consider instead using a fulltext index for what you want to do.

    select count(*) from yourtable where match(title, body) against ('some_word');
    

提交回复
热议问题