簡體   English   中英

最好的方法在MySQL中為一個別有用心的“喜歡%”請求存儲多個值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM