SQL Exercise: Name and country of referee who managed the final game
SQL soccer Database: Joins Exercise-9 with Solution
9. From the following tables, write a SQL query to find the referee who managed the final match. Return referee name, country name.
Sample table: soccer_country
Sample table: match_mast
Sample table: referee_mast
Sample Solution:
SQL Code:
SELECT b.referee_name, c.country_name
FROM match_mast a
NATURAL JOIN referee_mast b
NATURAL JOIN soccer_country c
WHERE play_stage='F';
Sample Output:
referee_name | country_name ------------------+-------------- Mark Clattenburg | England (1 row)
Code Explanation:
The provided query in SQL that retrieves information about the referee and country for matches in the final stage from the tables match_mast, referee_mast, and soccer_country.
The NATURAL JOIN keyword is used to join the tables based on columns with the same name in the tables match_mast, referee_mast, and soccer_country.
The condition filters the rows only for matches in the final stage, where play_stage is equal to 'F'.
Relational Algebra Expression:

Relational Algebra Tree:

Practice Online
Sample Database: soccer

Query Visualization:
Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Name and country of referee who managed the first game.
Next SQL Exercise: Referee who assisted in the opening match.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
What is the best way to paginate results in SQL Server?
SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, * FROM Orders WHERE OrderDate >= '1980-01-01' ) AS RowConstrainedResult WHERE RowNum >= 1 AND RowNum < 20 ORDER BY RowNum
Database: SQL Server
Ref: https://bit.ly/3MGrNlk
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
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