webent Posted July 22, 2008 Share Posted July 22, 2008 MySQL Version - 4.1.22-standard-log Hi, for the life of me I can't figure out why my query is failing, is it me or is it a bug? Correct me if I'm mistaken, but doesn't an "AND" statement require that it must meet the criteria on both sides of the statement? Here's my code with some values already in place... SELECT DISTINCT product_line FROM db.products WHERE product_vendor = 'TestingVendor' AND product_line = 'Automotive' OR product_line = 'Collectibles' OR product_line = 'VIDEO CONFERENCING' OR product_line = 'VIDEO EDITING - HARDWARE' Now, Automotive and Collectibles are not product_lines that belong to product_vendor = 'Testing_Vendor', so therefore shouldn't show up, but they are showing up, can someone please tell me what's going on with that? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 22, 2008 Share Posted July 22, 2008 When mixing AND and OR, use (..)s to indicate the correct logic Is it (A AND B) OR C or A AND (B OR C) Another thing you can do in your case is use "IN" SELECT DISTINCT product_line FROM db.products WHERE product_vendor = 'TestingVendor' AND product_line IN ( 'Automotive' , 'Collectibles' , 'VIDEO CONFERENCING' 'VIDEO EDITING - HARDWARE') Quote Link to comment Share on other sites More sharing options...
webent Posted July 22, 2008 Author Share Posted July 22, 2008 Thank you Barand, that worked nicely, had never seen the "IN" statement before, thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.