1

我有 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 中得到结果。

4

1 回答 1

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)
)
于 2013-02-14T10:50:21.820 回答