要在SQL查询复制结果

问题描述 投票:-1回答:1

我已经给10000 ID的列表会有些重复,我想在结果中显示。

例如,我想查询select * from table where id in (1,2,2,3,4)像下面显示的结果:

id | name | desc
----------------
1  | Abe  | name
2  | Bell | symp
2  | Bell | symp
3  | Cat  | anim
4  | Dan  | name
mysql sql
1个回答
1
投票

如果你喜欢打字,你可以做到这一点使用join。这是很容易与派生表:

select t.*
from table t join
     (select 1 as id union all
      select 2 as id union all
      select 2 as id union all
      select 3 as id union all
      select 4 as id 
     ) i
     on i.id = t.id;
© www.soinside.com 2019 - 2024. All rights reserved.