select c1, c2 from t1
where not exists
(
select 1 from t2
where t1.c2 = t2.c3
)
和
select c1, c2 from t1
where c2 not in
(
select c3 from t2
)
答案 0 :(得分:5)
not exists
会返回c2
等于NULL
not in
不会返回c2
等于NULL
DECLARE @t1 TABLE (c1 INTEGER, c2 INTEGER)
DECLARE @t2 TABLE (c3 INTEGER)
INSERT INTO @t1 VALUES (NULL, NULL), (1, NULL), (NULL, 1), (1, 1)
INSERT INTO @t2 VALUES (NULL), (1)
select c1, c2 from @t1 t1
where not exists
(
select 1 from @t2 t2
where t1.c2 = t2.c3
) -- returns (NULL, NULL) & (1, NULL)
select c1, c2 from @t1
where c2 not in
(
select c3 from @t2
) -- returns nothing