0

ここに と という名前の 2 つのテーブルがmain_tableありmain_table_replicaます。main_table_replicaのレプリカですmain_tablemain_tableしかし、問題は、またはのいずれかでデータを見つけることができることmain_table_replicaです。今、私は以下のようにクエリを実行しています。ここで組合を避けるにはどうすればよいですか?両方のクエリで唯一の変更はmain_tablemain_table_replicaです。

SELECT DISTINCT e.some_id
         FROM
             main_table e,   //Change is here
             main_table_join_one x     
             where  e.some_id = x.some_id(+)
             and (x.status in('A','I') or x.status is null)
             and e.code='XYZ' and e.second_code in('XYZ','ABC')


             UNION

        SELECT DISTINCT t.some_id
         FROM
             main_table_replica t,   //Change is here
             main_table_join_one xf     
             where  t.some_id = xf.some_id(+)
             and (xf.status in('A','I') or xf.status is null)
             and t.code='XYZ' and t.second_code in('XYZ','ABC')  

ありがとう!

4

1 に答える 1

2

この方法で 2 つの異なるテーブルからデータを取得することは、まさにunion目的です。それを避ける理由はありません。

ただし、ユニオンのスコープを縮小して重複を減らすことができます。

select distinct combined.some_id from (
        select e.some_id from main_table e
            union
        select t.some_id from main_table_replica t
    ) combined
    inner join  main_table_join_one x on
        combined.some_id = x.some_id(+) and
        (x.status in('A','I') or x.status is null) and
        combined.code='XYZ' and 
        combined.second_code in('XYZ','ABC');
于 2013-03-06T15:13:50.730 に答える