Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: count record from two tables with duplicate check

Re: count record from two tables with duplicate check

From: sim <jmenker_at_muenster.de>
Date: 14 Sep 2005 01:42:36 -0700
Message-ID: <1126687356.602882.198030@z14g2000cwz.googlegroups.com>


Seems like my first posting got lost. It's difficult to know which of the following sqls is the fastest. That depends on the design of your table (indexes) on the number of records on how up to date your statistics are and so on.

Nevertheless you could also try one of these:

SELECT COUNT(*)
FROM (SELECT AAA

        FROM   (SELECT EMP_NUM AAA FROM A
                UNION ALL
                SELECT EMP_NUM AAA FROM B)
        GROUP BY AAA
	   ) X


SELECT (SELECT COUNT(EMP_NUM) FROM A WHERE NOT EXISTS (SELECT 'X' FROM B WHERE B.EMP_NUM = A.EMP_NUM))

	   +
	   (SELECT COUNT(EMP_NUM) FROM B) CNT

FROM DUAL Received on Wed Sep 14 2005 - 03:42:36 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US