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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Field Names to set up a Union Query

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
0
0
US
Hey all, I'm trying to set up a Union Query and I've got a couple of questions for that.

First of all, all three queries are doing a Count of something different.

So my series of questions are this...
Can you set up a Union Query if all 3 Field Names are different?

If so, how?

If not, how do you Edit the name of the Field name in a Query?

Any help is good help. Thanks a lot.

Jason Alge
Jason.M.Alge@lowes.com

'There are three kinds of people: Those who can count and those who can't'
 
Example:

Select a, sum(b) as mysum form mytable
group by a
Union all
Select a, sum (c) as mysum from myothertable
group by a

 
assign column aliases in the first of the queries in the union:
Code:
select foo       as somename
     , count(*)  as totalrows
  from footable
group
    by foo
union all           
select bar       
     , count(*)  
  from barotable
group
    by bar
union all           
select qux
     , count(*)  
  from quxtable
group
    by qux

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (course starts January 9 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top