Sql – Alternative SQL ways of looking up multiple items of known IDs

sql

Is there a better solution to the problem of looking up multiple known IDs in a table:

SELECT * FROM some_table WHERE id='1001' OR id='2002' OR id='3003' OR ...

I can have several hundreds of known items. Ideas?

Best Answer

SELECT * FROM some_table WHERE ID IN ('1001', '1002', '1003')

and if your known IDs are coming from another table

SELECT * FROM some_table WHERE ID IN (
    SELECT KnownID FROM some_other_table WHERE someCondition 
)