w3resource

SQL Exercise: Stadium hosted the final match of EURO cup 2016

SQL soccer Database: Joins Exercise-13 with Solution

13. From the following tables, write a SQL query to find out which stadium hosted the final match of the 2016 Euro Cup. Return venue_name, city, aud_capacity, audience.

Sample table: soccer_venue


Sample table: soccer_city


Sample table: match_mast


Sample Solution:

SQL Code:

SELECT a.venue_name, b.city, a.aud_capacity, c.audence
FROM soccer_venue a
JOIN soccer_city b ON a.city_id=b.city_id
JOIN match_mast c ON a.venue_id=c.venue_id
WHERE play_stage='F';

Sample Output:

   venue_name    |    city     | aud_capacity | audence
-----------------+-------------+--------------+---------
 Stade de France | Saint-Denis |        80100 |   75868
(1 row)

Code Explanation:

The said query in SQL that selects the name of the venue where the final is played, the city in which the venue is located, the capacity of the venue, and the audience count for all matches in the "Finals" stage from the tables soccer_venue, soccer_city, and match_mast.
The JOIN keyword is used to join the tables together based on their city_id and venue_id columns.
The JOIN keyword is used to join soccer_venue with soccer_city on their city_id columns, and then join the resulting table with match_mast on their venue_id columns.
The WHERE keyword is used to filter records for matches in the "Finals" stage.

Relational Algebra Expression:

Relational Algebra Expression: Find the stadium hosted the final match of EURO cup 2016 along with the capacity, and audience for that match.

Relational Algebra Tree:

Relational Algebra Tree: Find the stadium hosted the final match of EURO cup 2016 along with the capacity, and audience for that match.

Practice Online


Sample Database: soccer

soccer database relationship structure

Query Visualization:

Duration:

Query visualization of Find the stadium hosted the final match of EURO cup 2016 along with the capacity, and audance for that match - Duration

Rows:

Query visualization of Find the stadium hosted the final match of EURO cup 2016 along with the capacity, and audance for that match - Rows

Cost:

Query visualization of Find the stadium hosted the final match of EURO cup 2016 along with the capacity, and audance for that match - Cost

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

Previous SQL Exercise: City where the opening match of EURO cup 2016 played.
Next SQL Exercise: Number of matches played at each venue and their city.

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