select id, bossid
from employees
where id in (22299, 22299)
这导致
id |bossid
22299|20529
我想要
id |bossid
22299|20529
22299|20529
有没有办法让db返回这样的结果?
答案 0 :(得分:0)
使用union作为
select id, bossid
from employees
where id = 22299
UNION
select id, bossid
from employees
where id = 22299
答案 1 :(得分:0)
一种方法使用union all
:
select id, bossid
from employees
where id in (22299)
union all
select id, bossid
from employees
where id in (22299);
另一个使用join
可能看起来像:
select e.id, e.bossid
from employees e join
(select 22299 as id union all select 22299
) ids
on e.id = ids.id;
或者,只需使用cross join
:
select e.id, e.bossid
from employees e join
(select 1 as n union all select 2
) ids;