<分区>
MySQL 中是否有任何方法可以使以下查询返回 3 个结果而不是 2 个?
select * from products p where p.id in (303022, 287769, 303022)
标签 mysql
<分区>
MySQL 中是否有任何方法可以使以下查询返回 3 个结果而不是 2 个?
select * from products p where p.id in (303022, 287769, 303022)
最佳答案
如果您想要两次 303022 的值,您可以对该行的查询进行 UNION ALL,否则,对于该查询,它将始终只返回两个(假设 id 在表中不重复):
select * from products p where p.id in (303022, 287769)
UNION ALL
select * from products p where p.id = 303022
关于mysql从包含重复项的列表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19729173/