ホームページ  >  記事  >  データベース  >  Oracle查询两表相差的数据

Oracle查询两表相差的数据

WBOY
WBOYオリジナル
2016-06-07 16:55:40974ブラウズ

原来以为not exists 会比not in 效率高,但在实际运用过程中,发现两表数据差不多的情况下,用另一种方式效率会更好. 原设计

  原来以为not exists 会比not in 效率高,但在实际运用过程中,发现两表数据差不多的情况下,用另一种方式效率会更好.

  原设计语句:

  select * from (select * from ex_22222 where exattribute1 = '13') K1 where not exists

  (

  select * from

  (

  select ex_22222.entityid from ex_22222,ut_users where exattribute1 = '13'

  and ex_22222.entityid = ut_users."UID"

  ) K2

  where K1.ENTITYID = K2.ENTITYID

  )

  新改进语句:

  select K1.ENTITYID,K2.ENTITYID from (select * from ex_22222  where exattribute1 = '13') K1,

  (

  select * from

  (

  select ex_22222.entityid from ex_22222,ut_users where exattribute1 = '13'

  and ex_22222.entityid = ut_users."UID"

  )

  ) K2

  where K1.ENTITYID = K2.ENTITYID(+)

  and K2.ENTITYID is null

linux

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。