w3resource

SQL Exercise: Name and country of referee who managed the first game

SQL soccer Database: Joins Exercise-8 with Solution

8. From the following tables, write a SQL query to find the referee who managed the opening 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 match_no=1;

Sample Output:

 referee_name  | country_name
---------------+--------------
 Viktor Kassai | Hungary
(1 row)

Code Explanation:

The provided query in SQL that retrieves information about the referee and country for the match with match_no equal to 1 from the tables match_mast, referee_mast, and soccer_country.
The NATURAL JOIN keyword is used to join the tables match_mast, referee_mast, and soccer_country based on columns with the same name in each table.
The condition filters only those rows for the match with match_no equal to 1.

Relational Algebra Expression:

Relational Algebra Expression: Find the name and country of the referee who managed the opening match.

Relational Algebra Tree:

Relational Algebra Tree: Find the name and country of the referee who managed the opening match.

Practice Online


Sample Database: soccer

soccer database relationship structure

Query Visualization:

Duration:

Query visualization of Find the name and country of the referee who managed the opening match - Duration

Rows:

Query visualization of Find the name and country of the referee who managed the opening match - Rows

Cost:

Query visualization of Find the name and country of the referee who managed the opening match - Cost

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

Previous SQL Exercise: Find the player who socred first goal of EURO cup 2016.
Next SQL Exercise: Name and country of referee who managed the final game.

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

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

 





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