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

Union query 1

Status
Not open for further replies.

fordtran

Programmer
Jun 15, 2005
101
ZA
I have two tables with the same (value) fields and I need to add each field of the two tables together. My query does not work - can somebody help.

I am in Access 2000

S$ = "Select sum(total) as Ttotal,sum(seland) as Tseland,sum(sesea) as Tsesea,sum(meland) as Tmeland,sum(mesea) as Tmesea,sum(rotor) as Trotor,sum(glider) as Tglider,sum(motorglider) as Tmotorglider, sum(military) as Tmilitary,sum(ldgsday) as Tldgsday,sum(ldgsnight) as Tldgsnight,sum(night)as Tnight,sum(actualIF) as Tactualif,sum(simif) as Tsimif,sum(flightsim) as Tflightsim,sum(crossc) as Tcrossc, sum(pic) as Tpic,sum(sic) as Tsic,sum(dualrec) as Tdualrec,sum(instruct) as Tinstruct from hours union all previoushours"

Thanks

fordtran
 
I think you need a little more in the Union statement ( At the very least:

[tt]<...> as Tinstruct from hours union all Select * From previoushours[/tt]

Which assumes that the fields in previoushours are in exactly the same order as hours.

You will need to [backet] hours as it is a reserved word.

It is always very acceptable to get a little more information than 'does not work'. :)
 
is this what you're looking for?
Code:
select sum(total) as Ttotal
     , sum(seland) as Tseland
     , sum(sesea) as Tsesea
     , sum(meland) as Tmeland
     , sum(mesea) as Tmesea
     , sum(rotor) as Trotor
     , sum(glider) as Tglider
     , sum(motorglider) as Tmotorglider
     , sum(military) as Tmilitary
     , sum(ldgsday) as Tldgsday
     , sum(ldgsnight) as Tldgsnight
     , sum(night)as Tnight
     , sum(actualIF) as Tactualif
     , sum(simif) as Tsimif
     , sum(flightsim) as Tflightsim
     , sum(crossc) as Tcrossc
     , sum(pic) as Tpic
     , sum(sic) as Tsic
     , sum(dualrec) as Tdualrec
     , sum(instruct) as Tinstruct 
  from ( 
       select * 
         from hours 
       union all 
       select *
         from previoushours
       ) as data

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top