So first of all, I manged to do something like this:
SELECT * FROM `trades`
WHERE 15003 NOT IN (`slot1`, `slot2`, `slot3`, `slot4`)
And this works correct, gives me rowes without product ‘15003’ in any of those columns.
But what if I don’t want to have any of ‘15003’ or ‘15004’ or ‘15008’ those in query?
I want to do it like this:
SELECT * FROM `trades`
WHERE 15003 NOT IN (`slot1`, `slot2`, `slot3`, `slot4`) AND
15004 NOT IN (`slot1`, `slot2`, `slot3`, `slot4`) AND
15008 NOT IN (`slot1`, `slot2`, `slot3`, `slot4`)
It works, but I think its not proper…
How can I optimize this?
Edit:
Each trade has its id and 4 slots.
This is a very poor design choice, exemplified by how much difficulty you’re having with this query. Instead of:
should be properly normalized to something like:
Which will allow you much more flexibility and make the queries MUCH easier to write.