首页  >  文章  >  数据库  >  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