Selecting multiple rows by ID, is there a faster way than WHERE IN

后端 未结 3 1661
太阳男子
太阳男子 2021-01-04 05:46

I have a SQL Table and I would like to select multiple rows by ID. For example I would like to get the row with IDs 1, 5 and 9 from my table.

I have been doing this

3条回答
  •  悲哀的现实
    2021-01-04 05:55

    I guess if you joined your table with a memory table indexed by a primary key, such as:

    declare @tbl table (ids int primary key)
    

    you could fill this table with the id's you need, and preform an optimized inner join.

    The problem could be the time it would take to fill it. I guess you could either have a linked server for that, or maybe use BCP utility to fill a temporary table this and then delete it.

提交回复
热议问题