Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

sql - SQL SELECT WHERE字段包含单词(SQL SELECT WHERE field contains words)

I need a select which would return results like this:

(我需要一个select会返回如下结果:)

SELECT * FROM MyTable WHERE Column1 CONTAINS 'word1 word2 word3'

And I need all results, ie this includes strings with 'word2 word3 word1' or 'word1 word3 word2' or any other combination of the three.

(我需要所有结果,即这包括带有'word2 word3 word1'或'word1 word3 word2'的字符串或三者的任何其他组合。)

All words need to be in the result.

(所有单词都需要在结果中。)

  ask by Mario M translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Rather slow, but working method to include any of words:

(相当慢,但工作方法包括任何单词:)

SELECT * FROM mytable
WHERE column1 LIKE '%word1%'
   OR column1 LIKE '%word2%'
   OR column1 LIKE '%word3%'

If you need all words to be present, use this:

(如果您需要出现所有单词,请使用:)

SELECT * FROM mytable
WHERE column1 LIKE '%word1%'
  AND column1 LIKE '%word2%'
  AND column1 LIKE '%word3%'

If you want something faster, you need to look into full text search, and this is very specific for each database type.

(如果你想要更快的东西,你需要查看全文搜索,这对每种数据库类型都是非常具体的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...