not in 和 not exists
CREATE TABLE #t1 ( c1 INT, c2 INT ); CREATE TABLE #t2 ( c1 INT, c2 INT ); INSERT INTO #t1 VALUES ( 1, 2 ); INSERT INTO #t1 VALUES ( 1, 3 ); INSERT INTO #t2 VALUES ( 1, 2 ); INSERT INTO #t2 VALUES ( 1, NULL ); SELECT * FROM #t1 WHERE c2 NOT IN ( SELECT c2 FROM #t2 ); ---->执行结果:无 SELECT * FROM #t1 WHERE NOT EXISTS ( SELECT 1 FROM #t2 WHERE #t2.c2 = #t1.c2 ); --->执行结果:1 3