mySQL select multiple ids
If you need to fetch several rows by their IDs in a single query, use the IN clause instead of chaining multiple OR conditions. It’s cleaner and easier to read.
SELECT * FROM tablename WHERE `active`='1' AND `id` IN ('107', '125') ORDER BY `id` DESC LIMIT 12
This grabs all rows where the id is either 107 or 125 and the row is active. You can add as many IDs as you need inside the IN() parentheses, separated by commas.
Earlier post on MySQL goes deeper.
This is much better than writing WHERE id = 107 OR id = 125 OR id = 130 ... — especially when the list of IDs comes from another query or an application. Just be careful with very large IN lists (thousands of values), as that can slow things down. In those cases, consider using a temporary table or a subquery instead.