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? Link to comment https://forums.phpfreaks.com/topic/116031-solved-mysql-seemingly-failing-simple-andor-query/ 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') Link to comment https://forums.phpfreaks.com/topic/116031-solved-mysql-seemingly-failing-simple-andor-query/#findComment-596736 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. Link to comment https://forums.phpfreaks.com/topic/116031-solved-mysql-seemingly-failing-simple-andor-query/#findComment-596754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.