w3resource

SQL Exercise: Find the final four teams in the tournament

SQL soccer Database: Joins Exercise-30 with Solution

30. From the following tables, write a SQL query to find the final four teams in the tournament. Return country name.

Sample table: soccer_country


Sample table: match_details


Sample Solution:

SQL Code:

SELECT country_name
FROM match_details a
JOIN soccer_country b
ON a.team_id=b.country_id
WHERE play_stage='S';

Sample Output:

 country_name
--------------
 France
 Germany
 Portugal
 Wales
(4 rows)

Code Explanation:

The said query in SQL that retrieves the country names of teams that have played in the "Semi-Finals" of a soccer tournament.
The JOIN clause joins the 'match_details' table and the 'soccer_country' table using the "team_id" and the "country_id" columns from the respective tables.
The WHERE clause retrieves data for teams that have played in the "Semi-Finals" of a soccer tournament.

Relational Algebra Expression:

Relational Algebra Expression: Find the final four teams in the tournament.

Relational Algebra Tree:

Relational Algebra Tree: Find the final four teams in the tournament.

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: Find 3 Lyon players participated in the EURO Finals.
Next SQL Exercise: Captains of the top four teams in the semifinals.

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