Home  >  Article  >  Database  >  Oracle查询两表相差的数据

Oracle查询两表相差的数据

WBOY
WBOYOriginal
2016-06-07 16:55:40974browse

原来以为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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn