mysql-使用in运算符返回查询中的所有行

qv7cva1a  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(377)

我试图提出以下问题:

SELECT * FROM Example WHERE id IN (1, 4 ,53 ,53, 95, 12, 54, 54)

我希望从示例中得到8个值,但我只得到6个值,因为ID53和ID54是重复的。有没有办法为每个id获取一个值?

dauxcl2d

dauxcl2d1#

如前所述,in子句中的重复值将被忽略。我已经用javascript解决了我的问题。

bybem2ql

bybem2ql2#

你需要使用 left join . 比如:

select e.*
from (select 1 as id union all select 4 union all select 53 union all select 53 union all
      select 95 union all select 12 union all select 54 union all select 54
     ) i left join
     example e
     on i.id = e.id;

相关问题