简体   繁体   English

SQL - 使用 AND 进行通配符搜索

[英]SQL - Wildcard search with AND

Below is the scenario.下面是场景。

We have a field named "Description", the requirement is:我们有一个名为“Description”的字段,要求是:

  1. User can give max 5 words to search the result.用户最多可以给出 5 个词来搜索结果。 eg : ab and cd and ef and gh and ij例如:ab 和 cd 和 ef 和 gh 和 ij
  2. It will give that description which has all the above 5 words in it.它将给出包含上述所有 5 个单词的描述。

Can anyone please tell me how can this be accomplished.谁能告诉我如何做到这一点。

Any guidance will be highly appreciated.任何指导将不胜感激。

Thanks and Regards, Aarti感谢和问候, Aarti

select description from tablename where 
description like '%word1%' and
description like '%word2%' and
description like '%word3%' and
description like '%word4%' and
description like '%word5%'

It would be useful to know what happens to "words" if they are less than 5. Are they null?如果“单词”小于 5,那么了解它们会发生什么会很有用。它们是否为空? Are they ''?他们是''吗? Example with null:空值示例:

....(description like '%word2%' or word2 is null) and...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM