954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

query with multiple 'OR' returns wrong results

This seems like it should be a simple query but I think I have my eyes in backwards...

Give me all the users living in Jefferson, Bingham, Butte, Bonneville and Madison counties in the state of Idaho.

SELECT * FROM table WHERE county='Jefferson' OR county='Bingham' OR county='Butte' OR county='Bonneville' OR county='Madison' AND state='ID'


What I get is all users living in EVERY Jefferson county in the U.S!!!! My state='ID' gets ignored and none of the other counties are searched (not even in the other states!).

I'm confused... LOL

(and I know this is gonna be one of those forehead slap moments!)

ppetree
Junior Poster
158 posts since Oct 2009
Reputation Points: 12
Solved Threads: 8
 
SELECT * FROM table WHERE (county='Jefferson' OR county='Bingham' OR county='Butte' OR county='Bonneville' OR county='Madison') AND state='ID'
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

doh!

Damn! I shoulda thought of that! Thanks!

ppetree
Junior Poster
158 posts since Oct 2009
Reputation Points: 12
Solved Threads: 8
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: