我有2个查询从同一个表中检索记录。我想把所有结果放在一张桌子里。
第一次查询
SELECT ID, NAME, FKNGRP
FROM EMPINFO
WHERE ID = ‘03’
AND SERIALNO = ‘N’
AND (FKNGRP = 1001 OR FKNGRP = 1002 )
第二次查询
SELECT ID, NAME, FKNGRP
FROM EMPINFO
WHERE ID = ‘04’
AND SERIALNO = ‘N’
AND (FKNGRP = 1001 OR FKNGRP = 1005 OR FKNGRP = 1009 )
我想结合这两个查询并在DB2中获得结果。
答案 0 :(得分:2)
SELECT ID, NAME, FKNGRP
FROM EMPINFO
WHERE
(
ID = ‘04’
and SERIALNO = ‘N’
AND FKNGRP in (1001, 1005, 1009)
)
or
(
ID = ‘03’
and SERIALNO = ‘N’
AND FKNGRP in (1001, 1002)
)