oracle查询一个表中又另一个表中没有的数据

吹雪 2008-09-14 09:35:45
A表中有telephone字段,caller字段,大概有二万条记录。

B表中有telephone字段。192条记录。

两个表没有建立关联。

B表中是所有telephone的列表(相当于主键)。

A表中是所有的记录,但是记录中的telephone有一部分在B表中有,有一部分没有。现在想查询所有A表中有而B表中没有的telephone字段值列表。

我试过:
select distinct telephone from a where telephone not in(select telephone from b)
这样查不出来,没有一条记录。

select distinct telephone from a where not exists(select 1 from b where a.telephone=b.telephone)
这样在plsql-developer里执行很久也没有返回。
...全文
3715 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangqicai110 2008-11-14
  • 打赏
  • 举报
回复
mark~~
内存泄漏 2008-09-17
  • 打赏
  • 举报
回复
表示该SQL采用左连接。。
上面相当于:
select distinct a.telephone ,b.telephone from a left join b on a.telephone = b.telephone
吹雪 2008-09-17
  • 打赏
  • 举报
回复
select distinct a.telephone,b.telephone from a,b where a.telephone = b.telephone(+)

请问一下后面的(+)是什么意思?
吹雪 2008-09-16
  • 打赏
  • 举报
回复
有没有办法一条sql语句可以把整个B表中不存在而A表中有的telphone列出来?
内存泄漏 2008-09-16
  • 打赏
  • 举报
回复
你这太奇怪了,select distinct telephone from a where telephone not in(select telephone from b)
这条语句是对的..

用左连接测一下是否可查出来??
select distinct a.telephone,b.telephone from a,b where a.telephone = b.telephone(+)

选出来符合你要求的记录是a.telephone不为空,b.telephone 为空的记录..
吹雪 2008-09-16
  • 打赏
  • 举报
回复
select distinct a.telephone,b.telephone from a,b where a.telephone = b.telephone(+)

请问一下后面的(+)是什么意思?
shakaqrj 2008-09-16
  • 打赏
  • 举报
回复
要高速,就要用联合查询

oracle中如果有minus那是最好,直接用就可以了

minus运算

返回在第一个查询结果中与第二个查询结果不相同的那部分行记录。

有哪些工种在财会部中有,而在销售部中没有?

exp:
select job from account

minus

select job from sales;

吹雪 2008-09-16
  • 打赏
  • 举报
回复
Select atp From
(Select distinct a.telphone As atp,b.telphone As btp from phonelog a,channel b where a.telphone = b.telphone(+))
Where btp Is Null

这样是否效率不高?是否有更高效率的解决方法?
zhoujianhei 2008-09-14
  • 打赏
  • 举报
回复
select * from a where telephone not in(select telephone from b where b.telephone=a.telephone)
supercow 2008-09-14
  • 打赏
  • 举报
回复
难道你的数据恰恰正好B的电话包含了那两万条电话的值?.... ft..
不如你先试试 join 看看右结果有没有出现NULL的, 如果没有,估计就是数据问题了吧.
zhoujianhei 2008-09-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhoujianhei 的回复:]
select * from a where telephone not in(select telephone from b where b.telephone=a.telephone)

[/Quote]
你以为这是在查啥?》
吹雪 2008-09-14
  • 打赏
  • 举报
回复
想查询所有A表中有而B表中没有的telephone字段值列表

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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