# Thread: Combined Sum of Query From Two Tables?

1. Registered User
Join Date
Dec 2010
Posts
36

## Unanswered: Combined Sum of Query From Two Tables?

I'm running a query to show the transfer fees spent by a club with data from two tables :

Code:
```SELECT SUM([Transfer Fee]) From [Summer_2001_2011] WHERE [New Club] LIKE 'Manchester City'
Union All
SELECT SUM([Transfer Fee]) From [Winter_2001_2011] WHERE [New Club] LIKE 'Manchester City'```
Shows the sum from each table :

Code:
```545.01
110.98```
What do I need to add to the query to show the total from both tables?

2. Registered User
Join Date
Aug 2004
Location
Dallas, Texas
Posts
831
Possibly a join with like condition? One select sum(Transfer Fee)....or do the union into tmp table and then sum total on Transfer Fee?

3. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
Code:
```SELECT SUM(subtotal) AS total
FROM ( SELECT SUM([Transfer Fee]) AS subtotal
FROM [Summer_2001_2011]
WHERE [New Club] = 'Manchester City'
UNION All
SELECT SUM([Transfer Fee])
FROM [Winter_2001_2011]
WHERE [New Club] = 'Manchester City' ) AS u```
oh, and has anyone said this yet...
Btw: this is a very good example on why such a table structure is a bad idea. You should have used a single table right from the start.
jk, i know they have

4. Registered User
Join Date
Aug 2004
Location
Dallas, Texas
Posts
831
Originally Posted by r937
oh, and has anyone said this yet...I believe so....
Btw: this is a very good example on why such a table structure is a bad idea. You should have used a single table right from the start.
jk, i know they have
This is true. So very true.

5. Registered User
Join Date
Dec 2010
Posts
36
Originally Posted by r937
Code:
```SELECT SUM(subtotal) AS total
FROM ( SELECT SUM([Transfer Fee]) AS subtotal
FROM [Summer_2001_2011]
WHERE [New Club] = 'Manchester City'
UNION All
SELECT SUM([Transfer Fee])
FROM [Winter_2001_2011]
WHERE [New Club] = 'Manchester City' ) AS u```
oh, and has anyone said this yet...
Btw: this is a very good example on why such a table structure is a bad idea. You should have used a single table right from the start.
jk, i know they have
Thanks and yes they have said it.

6. Window Washer
Join Date
Nov 2002
Location
Jersey
Posts
10,322
One of my probleams when they bring me in after everyone else has failed

"Who Freakin (or other expletives) built this pile of horse stuff (again)"

They don't like it, but I fix it

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•