happypete Posted October 4, 2013 Share Posted October 4, 2013 Hi, I'm trying the following query but it seems to ignore the part about the date.... "SELECT * FROM data WHERE incident = '1' OR incident = '2' OR incident = '3' AND (DATE(date) BETWEEN 2013-08-19 AND 2013-10-04)" I've tried different formats: "SELECT * FROM data WHERE incident = '1' OR incident = '2' OR incident = '3' AND (date >= '2013-08-19' AND date <= '2013-10-04')" some guidance in the right direction would be great! Quote Link to comment https://forums.phpfreaks.com/topic/282698-multiple-conditions-in-mysql-query-including-date/ Share on other sites More sharing options...
Solution requinix Posted October 4, 2013 Solution Share Posted October 4, 2013 (edited) AND has higher precedence than OR. That means you actually wrote something more like SELECT * FROM data WHERE (incident = '1') OR (incident = '2') OR (incident = '3' AND (DATE(date) BETWEEN 2013-08-19 AND 2013-10-04))Which isn't what you want. Use parentheses to change the outcome, or use IN and reduce the expression to a simpler X AND Y. SELECT * FROM data WHERE incident IN ('1', '2', '3') AND (DATE(date) BETWEEN 2013-08-19 AND 2013-10-04) Edited October 4, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/282698-multiple-conditions-in-mysql-query-including-date/#findComment-1452519 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.