0

例えば

簡略化されたケーステーブル:

テーブルBに欠落している行エントリを含むテーブルA

select count(1) from table_a; --> returns 5 results
select count(1) from table_b; --> returns 4 results
select count(1) from table_a, table_b2 b 
where b.id_ab like a.id_ab; --> returns 4 results
select count(1) from table_a, table_b2 b 
where b.id_ab not like a.id_ab; --> returns unexpected result

SQL:

これを試しましたが(例外)、エラーが発生しました。

select a.id_ab from table_a a, table_b b except select a.id_ab from table_a, table_b2 b 
where b.id_ab not like a.id_ab; 

またはそれを行うためにユニオンを使用する方法は?例えば

(Select * from table_a except select * from table_b) Union All (Select * from table_b     except select record_id from table_a);

期待される結果:

結果

ありがとうございました。

4

2 に答える 2

2
select a.id_ab 
from table_a a 
    LEFT JOIN table_b b on a.id_ab = b.id_ab 
where b.id_ab is null
于 2013-01-08T07:59:35.443 に答える
1

以下のクエリを使用します(左外部結合を追加)。

table_aで一致しないデータを取得します。

 select count(1) from table_a, table_b2 b 
 where b.id_ab(+) = a.id_ab;

欠落している行のみが必要な場合は、以下のクエリを使用してください

 select count(1) from table_a, table_b2 b 
 where b.id_ab <> a.id_ab;

クエリ間でUNIONを使用する場合、列は等しくなければなりません。

   SELECT col1,col2 from table_a
   UNION
   SELECT col1,col2 from table_b

しかし、好きではありません

  SELECT col1,col2 from table_a
   UNION
   SELECT col1 from table_b
于 2013-01-08T08:07:21.990 に答える