w3resource

SQL Exercise: City where the opening match of EURO cup 2016 played

SQL soccer Database: Joins Exercise-12 with Solution

12. From the following table, write a SQL query to find the city where the opening match of EURO cup 2016 took place. Return venue name, city.

Sample table: soccer_venue


Sample table: soccer_city


Sample table: match_mast


Sample Solution:

SQL Code:

SELECT a.venue_name, b.city
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 match_no=1;

Sample Output:

   venue_name    |    city
-----------------+-------------
 Stade de France | Saint-Denis
(1 row)

Code Explanation:

The said query in SQL that selects the name of the venue where match number 1 is played, and the city in which the venue is located from the tables soccer_venue, soccer_city, and match_mast.
The JOIN keyword is used to join the 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 filters data for the match with match number 1.

Relational Algebra Expression:

Relational Algebra Expression: Find the city where the opening match of EURO cup 2016 played.

Relational Algebra Tree:

Relational Algebra Tree: Find the city where the opening match of EURO cup 2016 played.

Practice Online


Sample Database: soccer

soccer database relationship structure

Query Visualization:

Duration:

Query visualization of Find the city where the opening match of EURO cup 2016 played - Duration

Rows:

Query visualization of Find the city where the opening match of EURO cup 2016 played - Rows

Cost:

Query visualization of Find the city where the opening match of EURO cup 2016 played - Cost

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

Previous SQL Exercise: Referee who assisted in the final match.
Next SQL Exercise: Stadium hosted the final match of EURO cup 2016.

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