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

How to Add Data From Different Tables

Status
Not open for further replies.

vvicin01

Programmer
Aug 14, 2001
21
0
0
US
I have three tables in a database that I would like to
add the totals of each column. The database is used to store hockey players goals and assist and other fields. I want to add the totals of each player from the three tables.
I know you can add the sum of a column, but what about a particular row.

Thanks
 
dear vvicin01

you could do it like this

Select sum(field1) + sum (field2) as total from sourcetable.

regards Astrid
 
Perhaps then, you could use a query to pull all of the columns into one table (or one result set) and then do a second query from that one, doing as Astrid suggested (adding the fields together).

Rayna
 
Dear vvicin,

sorry for not reading exactly your question,

If your tables are alike, which means all the fields you need in the tables are of the same structure of fields and datatypes, you could try to use a Union statement.

Select sum(field1) + sum (field2) as total from sourcetable1
Union
Select sum(field1) + sum (field2) as total from sourcetable2.

whihc you can requery on the fly:

SELECT Sum(total) AS jane
FROM [SELECT sum(field1) + sum (field2) as total from sourcetable1
union
SELECT sum(field1) + sum (field2) as total from sourcetable2 ]. AS [bob];


regards Astrid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top