Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: count record from two tables with duplicate check
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