Wednesday, March 21, 2012

Groupby Unions

hi
I have MSSQL query that performs multiple UNION ,but I would like to perform a GROUPBY on the whole result set.
How Can i do this?
plz help...
bonoWhat about creating a view with the union statement?
On the view you can perform the group by on the whole result set.

Sneaky Pie|||use pubs

select U.city, count(U.city)
from
(
select city from authors
union all
select city from publishers
) U
group by u.city|||Hi HanafiH,

your solution is much better than mine, I didn't know that this could work. So I've learned something new.

Thanks for that

Sneaky Pie

No comments:

Post a Comment