Besides the question above I’d like to know if there is any way to optimize this MySQL statement.
SELECT *
FROM `products`
WHERE
`category` = 3073 OR
`category` = 3074 OR
`category` = 3100 OR
`category` = 3102 OR
`category` = 3106 OR
`category` = 3109 OR
`category` = 3111 OR
`category` = 3115 OR
`category` = 3130 OR
`category` = 3134 OR
`category` = 3144 OR
`category` = 3146 OR
`category` = 3152 OR
`category` = 3157 OR
`category` = 3162 OR
`category` = 3163 OR
`category` = 3164 OR
`category` = 3166 OR
`category` = 3167 OR
`category` = 3168 OR
`category` = 3170 OR
`category` = 3171 OR
`category` = 3177 OR
`category` = 3181 OR
`category` = 3182 OR
`category` = 3184 OR
`category` = 3190 OR
`category` = 3191 OR
`category` = 3192 OR
`category` = 3213 OR
`category` = 3224 OR
`category` = 3227 OR
`category` = 3228 OR
`category` = 3235 OR
`category` = 3238 OR
`category` = 3239 OR
`category` = 3240 OR
`category` = 3244 OR
`category` = 3245 OR
`category` = 3246 AND
`active` = 1 AND
`price_notax` > 0 AND
`deleted` = 0
ORDER BY `position` ASC
LIMIT 0, 24;
This statement is also displaying the products which have field value of price_notax equal to 0, why? I stated the number need to be higher than 0…
Any help would be appreciated.
When that WHERE clause is evaluated, any of the ORed clauses being true will make the state of the AND clauses irrelevant. To correct this you must surround the set of OR clauses with parentheses so they are evaluated separately…
But to accomplish the same thing with greater readability, use an IN clause, instead: