2

と の 2 つのテーブルがtable1ありtable2ます。両方のテーブルに同じ列があります。

レコードの違いを抽出したい - つまり、 not in でレコードをtable1抽出し、 not inでtable2レコードを抽出します。table2table1

Oracle SysでSQLを使用してそれを行うにはどうすればよいですか?

4

6 に答える 6

3

使用できる1つの結果セットで両方のテーブルのすべての違いを取得するには

select columnlist
from tableA
minus
select columnlist
from tableB
union all
select columnlist
from tableB
minus
select columnlist
from tableA
于 2012-09-25T08:56:42.103 に答える
0
select t1.column1,t1.column2 from table1 t1 except select t2.column1,t2.column2 from table 2 t2 UNION all select t2.column1,t2.column2 from table 2 t2 except select t1.column1,t1.column2 from table1 t1
于 2012-09-25T08:57:51.023 に答える
0
select t1.Id,t1.name,t2.Id,t2.name from table1 t1 ,table2 t2 where t1.Id and t1.Name not in(select * from  table2) and t2.Id,t2.name not in (select * from table 2)
于 2012-09-25T08:58:39.367 に答える
0

どのテーブルに実際に行が含まれているかに関する追加情報を含む、RomanKonz のソリューション (私は通常、実際の UNION ALL / MINUS 部分を単純化するために WITH を使用します):

with 
  v_a as (
    select *
    from tableA), 
  v_b as (
    select *
    from tableB)
select * from 
(
 (select 'A only' src, v.* from v_a v
  minus 
  select 'A only' src, v.* from v_b v
 ) 
 union all
 (select 'B only' src, v.* from v_b v
  minus
  select 'B only' src, v.* from v_b v
 )
) order by primarykeycolumn, src 
于 2012-09-25T10:17:48.743 に答える
0

MINUS 1 つの SELECT ステートメントの結果セットを取得し、2 番目の SELECT ステートメントによっても返される行を削除します。

このクエリは、table1 にあるが table2 にはないすべての行を返します。

SELECT * FROM table1
MINUS
SELECT * FROM table2;
于 2012-09-25T08:54:53.180 に答える
0
select * from table1 where pk_col not in(select pk_col from table2)

select * from table2 where pk_col not in(select pk_col from table1)
于 2012-09-25T08:55:18.510 に答える