So I have a table with a column called id and in some rare cases a lot of the IDs(between 20-140 different IDs) listed don't need to be/can't be shown to the user. It's all based on different permissions.
SELECT * FROM `table` WHERE (`id` != 21474 OR 26243 OR 78634) AND `checked` = 5
Unfortunately there is no additional grouping a开发者_运维问答nywhere else in the DB that allows me to call out this section of IDs at once. So I'm looking if there is a better way of going about this or if I should ignore doing this during the mysql/SELECT statement and instead do it within like a PHP statement after everything is pulled. The problem with a PHP foreach later is the data that is pulled can be hundreds upon hundreds of rows so it will really slow down the page. As you can see in the above mysql query I was thinking of just listing out the IDs in one huge statement but I figured maybe there is a better way of going about this. 100 ORs just doesn't sound like the best possible solution.
Use the IN keyword,
SELECT * FROM `table` WHERE `id` NOT IN (21474, 26243, 78634) AND `checked` = 5
IN
statement is good, but be careful not to bump into max_allowed_packet
option of the server, if you query turns out toooooo long.
精彩评论