ITPub博客

首页 > 数据库 > Oracle > [Scripts]一个表中存在但另外一个表中不存在的SQL

[Scripts]一个表中存在但另外一个表中不存在的SQL

原创 Oracle 作者:pan_tian 时间:2014-07-03 11:58:57 0 删除 编辑
一个表中存在但另外一个表中不存在的SQL,两种写法:

NOT EXISTS
SELECT ip
FROM   login_log l
WHERE  NOT EXISTS (
   SELECT 1             -- it is mostly irrelevant what you put here
   FROM   ip_location i
   WHERE  l.ip = i.ip
   );

NOT IN
SELECT ip
FROM   login_log
WHERE  ip NOT IN (
   SELECT DISTINCT ip
   FROM   ip_location
   )

NOT EXISTS vs NOT IN深度阅读:Speeding Up Queries with Semi-Joins and Anti-Joins: How Oracle Evaluates EXISTS, NOT EXISTS, IN, and NOT IN 

<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26687597/viewspace-1207609/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Android开发环境搭建及HelloWorld(ADT-Bundle)
下一篇: 《极简欧洲史》简评
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2012-02-18

最新文章