-
Select COUNT(*)
hi,
How can I do to have one SELECT clause returning 1 rows with sum of counted rows in table t1 and T2 ..
select count(*) from t1
union all
select count(*) from t2
-
select (select count(*) from t1)+(select count(*) from t2) from dual;
"The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman
-
or ...
select sum(rc) from
(
select 1 rc from t1
union all
select 1 from t2
)
Must be a lot of ways of doing this.
-
Hi slimdave, I think I win on speed - "select count(*)" can use Index Fast Full Scan, "select 1" uses FTS (at least on the 100'000 row table I tried).
"The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman
-
how about ...
select sum(rc) from
(
select count(*) rc from t1
union all
select count(*) from t2
)
-
I still win on key-strokes
"The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman
-
damn you, Mr DaPi, damn you.
I win on being-able-to-see-the-execution-plan-through-autotrace!
-
Heh.
I'm with slimdave on this one. Oracle's inexcusable inability to show plans for SELECT-clause sub-SELECTs gives the nod to the UNION implementation.
- Chris
-
Victory Shriek!
Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
Looks like the Yanks are ganging up on me. You two must have done "new math" and are now the ones to find "union all" more intuitive than "+" - I gave up set theory at the axiom of choice.
Have good one!
P.S. slimdave, please don't make such a dreadful noise when I'm asleep!
"The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|