这样写SQL语句 为什么得不到正确结果?(20分)

F

fwcy

Unregistered / Unconfirmed
GUEST, unregistred user!
我有A数据库和B数据库
A库的数据如下:
001 111
002 111
003 111
004 111
B库的数据如下:
001 111
004 111
我想得到查询结果如下(找出A库中在B库中不存在的记录):
002 111
003 111

我这样写:
select A.字段1,A.字段2 from A
left outer join B
on A.字段1<>B.字段1
为什么不行?

 
select A.字段1,A.字段2 from A
where A.字段1 not in (select A.字段1 from B)
 
select * from a where a.字段1 not in (select 字段1 from b)
 
select A.字段,a.字段2
from table A
where A.字段 not exists(select * from table2)
 
SELECT A.F1,A.F2 FROM A
WHERE A.F1 NOT IN (SELECT F FROM B)
 
象你这样可能A里的所有都会出现
select A.字段1,A.字段2 from A
where not exsists(select * from B where B.字段1=A.字段1)
 
select code,aaa form a where not exists(select code from b where b.code=a.code)
 
答案已经出来了吧,同意 not exists哪种
 
up china_peng
 
谢谢各位,已经可以啦!
让我们共同提高!
 
多人接受答案了。
 

Similar threads

X
回复
12
查看
77
jsxjd
J
F
回复
8
查看
227
fossick
F
H
回复
13
查看
65
ldaan3
L
H
回复
8
查看
59
huangjiahan
H
顶部