简体   繁体   中英

SQL - Wildcard search with AND

Below is the scenario.

We have a field named "Description", the requirement is:

  1. User can give max 5 words to search the result. eg : ab and cd and ef and gh and ij
  2. It will give that description which has all the above 5 words in it.

Can anyone please tell me how can this be accomplished.

Any guidance will be highly appreciated.

Thanks and Regards, 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? Are they ''? Example with null:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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