Match at least 2 words

Hi

I need a query that will return all records that contain at least two words of a search phrase in a specific field.

How do I go about that?

Thx.
solutionwizAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
It can be as simple as:
To match an exact word:
Select * from TableName where Col1 = 'Word1' or Col1='Word2';

To match part of a word:
Select * from TableName where Col1 like '%Word1%' or Col1 like '%Word2%';
0
SharathData EngineerCommented:
Provide some sample data with expected result. Also what is your SQL Server version?
0
solutionwizAuthor Commented:
Select * from TableName where Col1 like '%Word1%' or Col1 like '%Word2%'; would give me all records that contain one of the words.
What I need is the records that contain at least two words out of a multi word phrase.
For example: When the search is "OAKWOOD MANOR MOTOR" I need all records that contain two of those words or all three, but not those that contain only one of them.
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

jimyXCommented:
I can think of something like this:
Select * from TableName where Col1 like '%OAKWOOD%MANOR%' or Col1 like '%MANOR%MOTOR%' or Col1 like '%OAKWOOD%MOTOR%';

Can the order of the words change?
0
solutionwizAuthor Commented:
MS SQL version is 9.00.4035.00
0
jimyXCommented:
If the order of the words might change, then:
Select * from TableName where Col1 like '%OAKWOOD%MANOR%' or Col1 like '%MANOR%MOTOR%' or Col1 like '%OAKWOOD%MOTOR%' or Col1 like '%MANOR%OAKWOOD%' or Col1 like '%MOTOR%MANOR%' or Col1 like '%MOTOR%OAKWOOD%';
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
solutionwizAuthor Commented:
Yes, the order of the words can be different accross records.
0
mkobrinCommented:
Select * from TableName where ((Col1 like '%word1%' and Col1 like '%word2%')  or (Col1 like '%word2%' and Col1 like '%word3%') or (Col1 like '%word1%' and Col1 like '%word3%'))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.