SELECT * FROM `TABLE` WHERE
(`PRIMARY_KEY`= `VALUE1`) OR
(`PRIMARY_KEY`= `VALUE2`) OR
(`PRIMARY_KEY`= `VALUE3`) OR
(`PRIMARY_KEY`= `VALUE4`) OR
(`PRIMARY_KEY`= `VALUE5`) OR ...
This works. But is there a faster way?
Using the value in (list) construct is not faster, but the SQL-code will be much easier to read/understand once someone needs to maintain the code.
SELECT *
FROM `TABLE`
WHERE `PRIMARY_KEY` in( `VALUE1`
, `VALUE2`
, `VALUE3`
, `VALUE4`
, `VALUE5`
)
Updated: Rewritten to reflect the feedback from the comments.
SELECT * FROM table WHERE primary_key IN (value1, value2, ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With