views:

14

answers:

2

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!

A: 

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' )
hsz
Adding parentheses made it work just as if I left off the last line. Meaning, it returned all colors, not just Red, White, Blue.
k00k
+1  A: 

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.

Ash Burlaczenko
That works, thanks @Ash!
k00k