I need to look up thousands of rows by ID, but the IDs come from outside the DB, so I can't get them from other tables like so:
SELECT * FROM some_table WHERE ID IN (
SELECT KnownID FROM some_other_table WHERE someCondition
)
Is there anything better than this:
SELECT * FROM some_table WHERE ID IN ('1001', '1002', '1003', …)
Can I parametrize such a query where the number of id's isn't fixed? Or do I just end up concatenating a big string together each time?
(I'm using sqlite, btw, but I'm curious about other databases too.)
Best Solution
I would create a temp table with the variable values and do a "
select were in
".