w3resource

SQL Exercise: Which player won Man of the Match at EURO cup 2016?

SQL soccer Database: Joins Exercise-34 with Solution

34. From the following table, write a SQL query to find out the player who was selected for the ‘Man of the Match’ award in the finals of EURO cup 2016. Return player name, country name.

Sample table: soccer_country


Sample table: match_mast


Sample table: player_mast


Sample Solution:

SQL Code:

SELECT a.player_name, b.country_name
FROM player_mast a 
JOIN match_mast c ON c.plr_of_match=a.player_id
AND c.play_stage='F'
JOIN soccer_country b
ON a.team_id=b.country_id;

Sample Output:

 player_name | country_name
-------------+--------------
 Pepe        | Portugal
(1 row)

Code Explanation:

The said query in SQL that retrieves information about the player of the match in the final stage of soccer matches, including their name and country from the tables player_mast, match_mast, and soccer_country.
The JOIN clause joins the 'player_mast' table alias as 'a' with the 'match_mast' table alias as 'c' based on the common column "plr_of_match" in 'c' and "player_id" in 'a'. Additionally, only rows where the "play_stage" column in 'c' has the value of 'F' will be joined. Then, the resulting table is joined with the 'soccer_country' table alias as 'b' based on the common column "team_id" in 'a' and "country_id" in 'b'.

Relational Algebra Expression:

Relational Algebra Expression: Find the player who was selected for the Man of the Match Award in the finals of EURO cup 2016.

Relational Algebra Tree:

Relational Algebra Tree: Find the player who was selected for the Man of the Match Award in the finals of EURO cup 2016.

Practice Online


Sample Database: soccer

soccer database relationship structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: All the captains and goalkeepers for all the teams.
Next SQL Exercise: Players who came onto the field during the first half.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.

SQL: Tips of the Day

How to drop all tables from a database with one SQL query?

USE Databasename

SELECT  'DROP TABLE [' + name + '];'
FROM    sys.tables

Ref: https://bit.ly/3PIUmPL

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook