2013-02-14 230 views
1

我有2個查詢從同一個表中檢索記錄。我想把所有的結果都放在一張桌子上。將2個sql查詢合併爲1個查詢

1查詢

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

家庭作業問題? (只是好奇) – vaisakh 2013-02-14 10:47:57

+1

在兩個語句之間添加單詞UNION或UNION ALL – twoleggedhorse 2013-02-14 10:50:03

回答

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) 
) 
+0

謝謝。它工作正常 – Jerin 2013-02-14 12:26:49