SQLITE select 掩码,如何包含重复项

SQLITE select mask, how to include duplicates as weel

我有一个这样的查询,我想return IN 案例中的所有值与匹配的行数。

SELECT ID、姓名、年龄来自 USERS WHERE id IN (1,75,75);

returns

1|约翰|25

75|山姆|30

然而我想要的是

1|约翰|25

75|山姆|30

75|山姆|30

这种事情在sql可能吗?如果你们对此有解决方案,我将不胜感激。

谢谢

您可以使用 join 代替:

select u.*
from (select 1 as id union all select 75 union all select 75) i join
     users u
     on u.id = i.id;

更简洁的格式使用values():

with i(id) as (
      values (1), (75), (75)
)
select u.*
from i join
     users u
     on u.id = i.id;