سؤال

The following query is not working the way I expect:

SELECT DISTINCT * 
FROM mytable 
WHERE MATCH (StrNum, StrName, StrType, TownName, Zip) AGAINST ('elm') 
AND Color = 'RED' OR Color = 'WHITE' OR Color = 'BLUE'

This is returning more results than I expect - it's not limiting my results to those on 'elm'.

If I remove the last line (AND Color...), I can see that my MATCH AGAINST is working just fine and is indeed limiting to just those on 'elm'.

Do I need to do a subquery or something to pull of the Color stuff? Proper syntax would be really helpful, thanks!

هل كانت مفيدة؟

المحلول

Could this be written like so

SELECT DISTINCT * FROM mytable 
WHERE MATCH (StrNum, StrName, StrType, TownName, Zip) AGAINST ('elm')
AND Color IN ('RED', 'WHITE', 'BLUE') 

Hope this helps.

نصائح أخرى

Maybe parentheses will help ?

SELECT DISTINCT * 
FROM mytable 
WHERE MATCH (StrNum, StrName, StrType, TownName, Zip) AGAINST ('elm') 
AND ( Color = 'RED' OR Color = 'WHITE' OR Color = 'BLUE' )

Using MATCH AGAINST requires atleast 4 characters for each word searched for (By default anyways) so 'Elm' would be ignored.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top