select value from temp_a a
where a.id between 1 and 100
and not exists(select * from temp_b b where a.value=b.value);
這時能查出結果
select value from temp_a a
where a.id between 1 and 100
and a.value not in(select value from temp_b);
此時查出的結果為空.
經過google終於找出原因: 內表(temp_b)有空值. 用not in得到的結果集都為空.以下是結論:
1、對於not exists查詢,內表存在空值對查詢結果沒有影響;對於not in查詢,內表存在空值將導致最終的查詢結果為空。
2、對於not exists查詢,外表存在空值,存在空值的那條記錄最終會輸出;對於not in查詢,外表存在空值,存在空值的那條記錄最終將被過濾,其他數據不受影響。