SQL Exercise: Referee who assisted in the final match
SQL soccer Database: Joins Exercise-11 with Solution
11. From the following tables, write a SQL query to find the referee who assisted the referee in the final match. Return associated referee name, country name.
Sample table: asst_referee_mast
Sample table: soccer_country
Sample table: match_details
SELECT ass_ref_name, country_name FROM asst_referee_mast a JOIN soccer_country b ON a.country_id=b.country_id JOIN match_details c ON a.ass_ref_id=c.ass_ref WHERE play_stage='F';
ass_ref_name | country_name --------------+-------------- Simon Beck | England Jake Collin | England (2 rows)
The provided query in SQL retrieves information about the assistant referee and country for matches in the final stage from the tables asst_referee_mast, soccer_country, and match_details.
The JOIN keyword is used to join the tables based on columns specified in the ON clause. The asst_referee_mast and soccer_country are joined on the country_id column, while asst_referee_mast and match_details are joined on the ass_ref_id column.
The condition filters rows for matches in the final stage, where play_stage is equal to 'F', will be selected.
Relational Algebra Expression:
Relational Algebra Tree:
Sample Database: soccer
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Referee who assisted in the opening match.
Next SQL Exercise: City where the opening match of EURO cup 2016 played.
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
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- 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