Upgrade to MySQL 5 and create a view for your subquery in the original post. Then it should work properly. Then you don't need to update your code if for instance you want to add additional threads in the future. Without the subquery, you would most likely need a prior query that builds your array to check against the IN clause. Though depending on the where clauses, two queries may be more intensive. Unless you use stored procedures.