1.查询A表中存在而B表中不存在的数据

1.1 描述:表A中有一tel字段,表B中有一tel字段,两个字段存储的内容部分相同,现要查询A表tel字段中有而B表tel字段中没有的数据

1.2 有三个select关键字的查询语句

select tel
from A
where A.tel not in (
  select tel
  from A
  where A.tel in(
    select tel
    from B
)
)

  执行效果:效率极低,十万级左右的数据量运行了10min没有查询出结果,逻辑有环状结构的错误

1.3 有两个select关键字的查询语句

select tel
from A
where A.tel not in(
  select tel
  from B
)

  执行效果:效率较低

 

1.4 利用minus进行两表联查

select tel from A
minus
select tel from B;

  执行效果:效率最高且会自动去重

1.5 利用exists关键字

select tel
from A
where not exists(
  select tel
  from B
  where B.tel=A.tel
) ;

  执行效果:速度稍微比1.3的方法快一点

posted on 2018-04-13 16:38  xiangxiantao  阅读(212)  评论(0编辑  收藏  举报