What is the best way to select multiple rows by ID in sql?

后端 未结 5 1198
南方客
南方客 2021-02-03 23:37

I need to select multiple records

I use

SELECT *
FROM `table`
WHERE `ID` =5623
   OR `ID` =5625
   OR `ID` =5628
   OR `ID` =5621

this

5条回答
  •  孤街浪徒
    2021-02-03 23:57

    On top of what the people stated (where id in):

    1) iF there are a lot of IDs, better to stick them into a temp table and run a join with that temp table

    2) Make sure your table has an index on id

    3) If the real-timeliness of the data is not critical, put the query results in a cache on the application side

提交回复
热议问题