This one is probably "close enough"
Q1) one two three
Q1) should give a simple query
SELECT * FROM `myTable` WHERE `myField` LIKE '%one%' AND `myField` LIKE '%two%' AND `myField` LIKE '%three%';
But it doesn't account for whole words, it will, for example, match on "anyone" and "someone". More below. These are mostly incorrect:
Q2) "one two" three
Q2) should give
SELECT * FROM `myTable` WHERE `myField` LIKE '%one two%' AND `myField` LIKE '%three%'
Though the liklihood is slim, it would match on "someone two". The % is a wildcard character, when first it means "anything before" and last, "anything after." What you'd need here is some form of
mySQL regexp [dev.mysql.com]. Something like
select * from `myTable` where `myField` regexp '[[:<:]]one two[[:>:]]' and `myField` like '%three%'
or better,
select * from `myTable` where `myField` regexp '[[:<:]]one two[[:>:]]' and `myField` regexp '[[:<:]]three[[:>:]]'
[[:<:]] and [[:>:]] being word boundaries. You can test this on the command line:
select 'zero one two three four' regexp '[[:<:]]one two[[:>:]]';
--> 1
select 'zero one OOPS two three four' regexp '[[:<:]]one two[[:>:]]';
-- 0
Same with this one.
Q3) one two -three
Q3) should give
SELECT * FROM `myTable` WHERE `myField` LIKE '%one two%' AND `myField` NOT LIKE '%three%'
select * from `myTable` where `myField` regexp '[[:<:]]one two[[:>:]]' and `myField` not regexp '[[:<:]]three[[:>:]]'
There's no sense in extracting too many results then slogging through them in your programming, this makes for excessive use of resources and slow queries. You can do the regexps directly in the selects, see link above for more options. Though they are often more difficult to compose, regexps are more efficient than 'like' anyway.