![](/img/trans.png)
[英]SQL query to match atleast n characters in a string even if some characters are missed in the middle
[英]Using SQL to match characters in query string
我的問題是 我在使用sql來匹配查詢的部分時遇到問題。 例如,我想要這樣的語句:
SELECT * FROM {table} WHERE {table}.title LIKE '%term%';
其中term是一些搜索項,而table是我要查詢的表。 該語句在幾乎所有情況下都可以正常工作。 當查詢詞比數據庫中的查詢詞長時,就會出現此問題。 例如:
(assuming there is an entry in {table} with title="foobar")
SELECT * FROM {table} WHERE {table}.title LIKE '%foobars%';
由於s,以上內容不匹配foobars = foobar。
我可以用什么來克服這個問題?
謝謝。
在sql中,您可以執行'somestring' LIKE CONCAT('%',title,'%')
,這是一個類似反向的語句,但是您必須要小心,因為性能相當慢。 但是對於您的問題,您應該嘗試:
(assuming there is an entry in {table} with title="foobar")
SELECT * FROM {table} WHERE '%foobars%' LIKE CONCAT('%', {table}.title,'%');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.