[英]Best way to store multiple values in MySQL for an ulterior “like %” request?
我正在运行一个带有分类广告的网站,我想设置一个功能,当新广告与某些模式匹配时,该功能将发送电子邮件警报。
这个想法是允许用户存储倍数模式,然后对他们执行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中存储模式的最佳方法是什么?
一旦尝试
select ad from table where content REGEXP 'this|that'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.