The following query
SELECT * FROM workshops
WHERE workshop_zipcode LIKE '75___'
OR workshop_zipcode LIKE '77___'
AND workshop_category = 14
AND active = 1
AND workshop_date >= NOW()
ORDER BY workshop_date ASC
don’t generate any errors, and actually work, but with a little problem : this part
AND workshop_date >= NOW()
don’t filter anything, itried to replace the comparative sign with an equal, and the same list is retrieved.
the two first AND works well, but the third don’t.
You need to parenthesize your
ORcondition Like this:Without parenthesis you are in essence calling this:
This is because
ANDis calculated beforeOR. See this referencehttp://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html