我是 SQL 新手。我正在使用Oracle10g。我有以下查询。它有 3 个部分,并且正在对所有三个部分进行 UNION。但是在每个查询中,除了连接表之外,大多数逻辑都是常见的。是否可以避免 UNION 并将所有内容放在一个块中?
SELECT DISTINCT e.some_id
FROM
main_table e,
main_table_join_one x //only change
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 ef.some_id
FROM
main_table ef,
main_table_join_two xf //only change
where ef.some_id = xf.some_id(+)
and (xf.status in('A','I') or xf.status is null)
and ef.code='XYZ' and ef.second_code in('XYZ','ABC')
UNION
SELECT DISTINCT eff.some_id
FROM
main_table eff,
main_table_join_three xff //only change
where eff.some_id = xff.some_id(+)
and (xff.status in('A','I') or xff.status is null)
and eff.code='XYZ' and eff.second_code in('XYZ','ABC')
谢谢!