user8696813
user8696813

Reputation: 11

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

Upvotes: 1

Views: 44

Answers (1)

George Menoutis
George Menoutis

Reputation: 7240

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...

Upvotes: 1

Related Questions