Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

union help

Status
Not open for further replies.

Moxy1

Programmer
Aug 29, 2002
75
US
I have about 3 SQLs that I would like to join together with a Union. The problem that I'm having is with the Group by. Basically what I have is:

select location, '1', count(location)

union

select location, '2', count(location)

union

select location, '3', count(location)


Any ideas?


 
You wanted this ?
select location, '1', count(location) group by location
union
select location, '2', count(location) group by location
union
select location, '3', count(location) group by location

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You wanted this ?
select location, '1', count(location) from ... group by location
union
select location, '2', count(location) from ... group by location
union
select location, '3', count(location) from ... group by location
Or this ?
select location, sum(mycount) total
from (
select location, count(location) mycount from ... group by location
union all select location, count(location) from ... group by location
union all select location, count(location) from ... group by location
) u group by location

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH,

I've noticed you around several of the other forums here helping out. Is there anything you don't know?

As always Thank You!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top