如何从表A里抽取表B里没有的纪录 有共同的key字段

bubu198 2003-12-26 10:41:01
请给出例子
...全文
28 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
aiu 2004-01-20
  • 打赏
  • 举报
回复
什么啊 人家问的是比较记录 搞什么字段相同来比较 还搞什么外链接和内连接 哈。。
leecooper0918 2004-01-20
  • 打赏
  • 举报
回复

人家问的是比较记录 搞什么字段相同来比较
---------------------------------------
faint, 搞不懂你在说什么?


请看清楚楼主的问题再发言

如何从表A里抽取表B里没有的纪录 有共同的key字段
----------------------------------------------
nicolas1999king 2004-01-18
  • 打赏
  • 举报
回复
agree on leecooper0918(爱一个人好难) .
yangguang1219 2004-01-18
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where a.id=b.id)
这里的1代表什么啊
chanet 2003-12-27
  • 打赏
  • 举报
回复
可用使用 minus 关键字.
如果两个表的结构是相同的话:
select * from a minus select * from b; <- (显示在 A 表里,B 表没有的记录)

也可以指定字段:
select field1,field2 from a minus select field3,field4 from b

注意: 只有字段类型相同才可以进行比较.
qiansl 2003-12-26
  • 打赏
  • 举报
回复
左(右)连接其实也没什么的,写一个就知道了
leecooper0918 2003-12-26
  • 打赏
  • 举报
回复
a.keycol=b.keycol(+) means left join.
a.keycol(+)=b.keycol means right join.

if you are using oracle 9i now, you can use left(right) join in
your sql statements,because oracle 9i supports SQL99 standard.

BTW: you may read some oracle sql/plsql ariticles and documentation
to learn more about it.

seutxf77 2003-12-26
  • 打赏
  • 举报
回复
why???please tell me!!Thanks....
what mean "b.keycol(+)"??????I have never saw it!!
leecooper0918 2003-12-26
  • 打赏
  • 举报
回复
Do not use NOT IN statements, because it's efficiency is very very low.

Try this:
select a.* from a,b where a.keycol=b.keycol(+) and b.keycol is null
seutxf77 2003-12-26
  • 打赏
  • 举报
回复
SQL>select * from a,b where a.key not in (select b.key from b)
seutxf77 2003-12-26
  • 打赏
  • 举报
回复
Thanks !!!
whatwhynot 2003-12-26
  • 打赏
  • 举报
回复
select a.* from a,b where a.keycol=b.keycol(+);
这是外连接,意思就是扩展b表!!
LGQDUCKY 2003-12-26
  • 打赏
  • 举报
回复
.keycol=b.keycol(+) means left join.
a.keycol(+)=b.keycol means right join.
用这样的方法效率好点:
beckhambobo 2003-12-26
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where a.id=b.id)

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧