如何使SQL返回相同的数据

时间:2016-12-06 17:45:24

标签: sql

select id, bossid
from employees
where id in (22299, 22299)

这导致

id   |bossid
22299|20529

我想要

id   |bossid
22299|20529
22299|20529

有没有办法让db返回这样的结果?

2 个答案:

答案 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;