I have a query that displays the total amount of matches won by individual teams in the database,
select t.name, count(*) 'Matches_Won'
from test.team t
inner join test.match_scores m on m.winner = t.id
group by t.name
order by Matches_Won desc;
Another query prints out the total number of Matches Won by the Individual Teams in the database,
select t.name, count(*) 'Matches_PLayed'
from test.team t
inner join test.match_scores m on m.home_team = t.id or m.away_team = t.id
group by t.name
order by Matches_Played desc;
Now, I am trying to combine these two queries, I want a table with three columns,
- Team Name
- Matches Played
- Matches Won
I tried to union the two queries, but it didn't work. Anyone who can guide me on this?
**EDIT: **
This is the Team Table
This is the Match Scores Table. In this table, the columns "Home Team", "Away Team" represents the Goals scored by respective team and the "Winner" is the foreign key, referring to the Team Table.

