Creating a query from two different tables where columns have the same data

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
175
Hello guys, one more time I need your precious help.

I have a table with football match results and I would like to calculate the total statistics for the teams either playing at Home or Away.

So far I have managed to calculate statistics where the teams have played at home or away (it is easy as I group data based on one column) but when it comes to total statistics I can't combine data from the two different columns...

Any ideas? Let's say that the table is as simple as the below.

PS. I could combine the two separate tables I have created with the data for home and away statistics, but in this way, there are teams from the second table that do not exist in the first one and vice versa. Some may have played Away but not yet at Home and this creates more records in one table than the other.

Thanks!

HOMEAWAYRESULT
ArsenalChelsea1
ChelseaArsenalX
ArsenalLester2
LesterArsenal1
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello guys,

I think I did it, I had to use the UNION clause to combine the two tables (Home and Away). After some trials, I think I am in a position to combine the Home and Away columns without losing records!

Thank you for your attention though!
 
Upvote 0
Thank you Jack but I have already tried to build my own model.

Unfortunately I can't still combine the two tables together. Any ideas about that?

I have created two tables A & B.

A, includes the fixtures of the Home team (taken from the master table of results) and B that of the Away team.

Of course, you can have the same teams in both tables in the majority of data, but if a team has only played at Home or Away it may be included only in one of them.

So the issue is how can I combine the two tables and get the combined data per team either played at Home or Away.

I have created the below UNION query to join the tables but I can't combine the numerical data.

For instance, I want to populate the average odds from both tables for the win of the teams. n the A table is it called ODDS_FT_1 and in the B table is called ODDS_FT_2.

How these columns from both tables could be combined to bring the average of both?



SELECT

A.League,
A.Home
FROM
A
LEFT JOIN
B
ON
(A.Home = B.Away) AND (A.League = B.League)
GROUP BY
A.League, B.Home

UNION SELECT

B.League,
B.Away
FROM
A
RIGHT JOIN
B
ON
(A.Home = B.Away) AND (A.League = B.League)
GROUP BY
B.League, B.Away;
 
Upvote 0
I gave the link so you could compare your data model. I found this article that may help you with your calculations.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top