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

一个表中存在但另外一个表中不存在的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 

你可能感兴趣的:([Scripts]一个表中存在但另外一个表中不存在的SQL)