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

Home -> Community -> Usenet -> c.d.o.server -> Re: SELECT COUNT(*) FROM TABLE query problem

Re: SELECT COUNT(*) FROM TABLE query problem

From: M Hashim <m.a.n.hashim_at_sympatico.ca>
Date: Fri, 11 Oct 2002 12:29:18 -0700
Message-ID: <XYCp9.31367$da7.669161@news20.bellglobal.com>


Note: without a join between the 2 tables, you would end up with a cross-product total; e.g
select count(t3.col1)+count(t2.col1)
from t2,t3;
data t2 has 1 record;

        t3 has 2 records
total will be 4

Be careful on performance, with some fancy union, assuming all you want is the sum of the 2 tables, then you could do the following;

select (select count(*) from t3)+(select count(*) from t2) from dual;
the result would be 3.

"Harry Sheng" <hsheng_at_innovance.com> wrote in message news:hHBp9.15301$H67.69008_at_tor-nn1.netcom.ca...
> select sum(cnt)
> from (select count(*) cnt from table1
> union
> select count(*) cnt from table2
> )
>
> "Monty" <mmontreaux_at_hotmail.com> wrote in message
> news:6284dd3.0210110547.61cfcd4c_at_posting.google.com...
> > Hi there - the following hypothetical query is what I want but I can't
> > figure out how to correctly formulate it (actually the real query is
> > significantly more complex but the underlying problem with it
> > expressed in the query below. Furthermore I don't want to have to
> > perform two queries to resolve my problem).
> >
> > Basically I'm wanting to retrieve the total number
> >
> > Ideas anyone?
> >
> > Monty
> >
> > SELECT t1.COUNT(*), t2.COUNT(*)
> > FROM tablename1 t1, tablename2 t2;
>
>
Received on Fri Oct 11 2002 - 14:29:18 CDT

Original text of this message

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