最好的方法在MySQL中为一个别有用心的“喜欢%”请求存储多个值?

时间:2018-11-29 09:08:41

标签: php mysql json

我正在运行一个带有分类广告的网站,我想设置一个功能,当新广告与某些模式匹配时,该功能将发送电子邮件警报。

想法是允许用户存储倍数模式,然后对它们执行SELECT:

select ad from table where (content LIKE '%this%' OR content LIKE '%that%')

当然,我事先不知道用户需要多少个图案。

一种解决方案是为每个用户和每个模式创建一行,并通过连接表进行选择,但是我担心数据库的性能。

我已经考虑过JSON数据,但是我不知道如何做这样的事情:

select ad from table where content like (["this","that"])

或者也许有更好的方法?

修改

查看了最初的答案(谢谢)后,我意识到我不够清楚。

模式也将存储在数据库中,最终请求应类似于:

select ad from table where content LIKE (select *something* from pattern_table where userId = 123)

主要问题是:将图案存储在pattern_table中的最佳方法是什么

1 个答案:

答案 0 :(得分:0)

一旦尝试

select ad from table where content REGEXP 'this|that'