Skip to content
Advertisement

mysql query – clash between not in and/or

I’m trying to get all my products , from A specific categories and without some products from those categories .

i did this query:

The problem is that i’m still getting products with the string ‘SPLA’ or ‘SA OLP’ – because the NOT IN clash with the categories

How to solve it ?

Advertisement

Answer

As a starter: always use standard join (with the on keyword) rather than old-school implicit joins (with commas in the from clause): this old syntax has fallen out of favor decades ago and should not be used in new code.

Then: you need multiple like conditions rather than in. If you have many values, regexp matching comes handy to shorten the syntax:

Note that I used table aliases to shorten the syntax. I also remove the backticks around identifiers: most of the time they are not needed, and just make the query less easy to follow (you can add them back if this causes issues).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement