>  기사  >  데이터 베이스  >  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으로 문의하세요.