Author |
Topic |
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2008-03-20 : 07:19:57
|
i make a union query :select sum(*),reason from (select count(*),reason from table1 group by reasonunion allselect count(*),reason from table2 group by reason)group by reason the outer SUM(*) dosent work -why?thnaks in advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-20 : 07:21:18
|
[code]select sum(cnt),reason from (select count(*) as cnt,reason from table1 group by reasonunion allselect count(*),reason from table2 group by reason) Tempgroup by reason[/code]Edit: added table alias for derived table.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
jrogers
Starting Member
34 Posts |
Posted - 2008-03-20 : 07:22:52
|
[code]select sum([count]),reason from (select count(*) [count],reason from table1 group by reasonunion allselect count(*),reason from table2 group by reason) testgroup by reason[/code] |
 |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2008-03-20 : 07:39:24
|
i did like this : SELECT sum(cnt),reasonfrom(SELECT COUNT(*) AS cnt, ReasonFROM Tbl_reason2007WHERE (Company = 'latest') group by reasonUNION ALLSELECT COUNT(*), reasonFROM Tbl_reason2008WHERE company = 'latest' group by reason) group by reason and i get : quote: Incorrect syntax near the keyword 'group'.
why - i did the same as the xample you gave me?thnaks in advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-20 : 07:42:21
|
look at jrogers example... (harsh did a typo i think )Em |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-20 : 07:43:53
|
See my edited post.Elan,Yes it was typo Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2008-03-20 : 07:51:19
|
first thanks all of u!about the Temp table -this meaans a table called "temp" is created in the fly or what?thnaks i nadvancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-20 : 07:54:18
|
it doesn't really exist, it's just a derived table for use in your queryEm |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-20 : 07:54:47
|
It is not actual table, it is resultset which is referred to by given alias.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2008-03-20 : 09:34:31
|
ok thnaks allIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|