以下のSQLクエリがあります。私はオラクル10gを使用しています。ここでは、両方のクエリの結果を組み合わせています。
select distinct combined.some_id from (
SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H')
union all
SELECT DISTINCT e.some_id FROM tableA_Replica e where
e.some_code ='ABC' and e.code_two IN('S','H') and e.some_id NOT IN ( SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H'))
) combined,tableA_Replica_join_table_ONE x where
combined.some_id = x.some_id(+)
AND (x.status IN('ACTIVE','INACTIVE'))
UNION
select distinct combined.some_id from (
SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H')
union all
SELECT DISTINCT e.some_id FROM tableA_Replica e where
e.some_code ='ABC' and e.code_two IN('S','H') and e.some_id NOT IN ( SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H'))
) combined,tableA_Replica_join_table_TWO x where
combined.some_id = x.some_id(+)
AND (x.status IN('ACTIVE','INACTIVE'))
両方のクエリで、以下の部分は共通です。
SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H')
union all
SELECT DISTINCT e.some_id FROM tableA_Replica e where
e.some_code ='ABC' and e.code_two IN('S','H') and e.some_id NOT IN ( SELECT DISTINCT l.some_id FROM tableA l where
l.some_code ='ABC' and l.code_two IN('S','H'))
両方のクエリでコードの重複を避けるにはどうすればよいですか?