select c from a where not exist(select c from b where a.c=b.c)
select c from a where not exists(select c from b where a.c=b.c)
对,就是这个 select c from a where not exists(select c from b where a.c=b.c)
select c from a where not exists(select c from b where a.c=b.c)
select * from A left join B on A.C=B.C where B.C is null
select c from b where c no in (select c from a) 这样写感觉容易理解啊!
select c from a where not exists(select c from b where a.c=b.c)
select c from A where c not in (select c from B)
SELECT a.c FROM a LEFT OUTER JOIN b ON a.c = b.c WHERE (b.c IS NULL)
select c from a where c not in (select c from b)
a表,b表 ------- c c 1 2 2 1 3 3 4 1当然是:select c from a where c not in (select c from b)结果是:4 而下面 select c from a where not exists(select c from b where a.c=b.c)结果是:1,2,4 当然是不正确的
select c from a where not exists(select c from b where a.c=b.c)
select c from a where not exists(select c from b where a.c=b.c) 也是正确
select c from a where c not in (select c from b) 和 SELECT a.c FROM a LEFT OUTER JOIN b ON a.c = b.c WHERE (b.c IS NULL) 两者都对,前者用嵌套,后者用左外连接。但是如果数据量比较大,后者的效率要高的多
同意楼上的说法! 用left outer join
SELECT DISTINCT C FROM A JOIN B ON A.C=B.C AND C NOT IN (SELECT DISTINCT C FROM B)
select c from a where not exists(select c from b where a.c=b.c)
left join B
on A.C=B.C
where B.C is null
这样写感觉容易理解啊!
FROM a LEFT OUTER JOIN
b ON a.c = b.c
WHERE (b.c IS NULL)
-------
c c
1 2
2 1
3 3
4 1当然是:select c from a where c not in (select c from b)结果是:4
而下面
select c from a where not exists(select c from b where a.c=b.c)结果是:1,2,4 当然是不正确的
也是正确
和
SELECT a.c
FROM a LEFT OUTER JOIN
b ON a.c = b.c
WHERE (b.c IS NULL)
两者都对,前者用嵌套,后者用左外连接。但是如果数据量比较大,后者的效率要高的多
用left outer join