我正在尝试进行此查询:
SELECT * FROM Example WHERE id IN (1, 4 ,53 ,53, 95, 12, 54, 54)
我希望从示例中获得 8 个值,但我只获得 6 个值,因为 ID 53 和 ID 54 重复。有没有办法为每个ID获取一个值?
最佳答案
您需要使用左连接
。像这样的东西:
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;
关于MYSQL - 使用 IN 运算符返回查询中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907325/