SQL Exercise: Where was the final match of the EURO cup 2016 held?
SQL soccer Database: Joins Exercise-1 with Solution
1. From the following table, write a SQL query to find out where the final match of the EURO cup 2016 was played. Return venue name, city.
Sample table: soccer_venue
Sample table: soccer_city
Sample table: match_mast
Sample Solution:
SQL Code:
SELECT venue_name, city
FROM soccer_venue a
JOIN soccer_city b ON a.city_id=b.city_id
JOIN match_mast d ON d.venue_id=a.venue_id
AND d.play_stage='F';
Sample Output:
venue_name | city -----------------+------------- Stade de France | Saint-Denis (1 row)
Code Explanation:
The given query in SQL that returns a list of all the venue names and their corresponding cities where matches with play_stage 'F' were held..
The query uses two JOIN operations to link the soccer_venue and soccer_city tables based on the common city_id column. It then uses a third JOIN operation to link the match_mast table with the previous result set based on the common venue_id column. The ON condition for this JOIN specifies that only rows where the play_stage column equals 'F' (which likely stands for "finals") are included in the final result set.
Relational Algebra Expression:

Relational Algebra Tree:

Practice Online
Sample Database: soccer

Query Visualization:
Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: SQL JOINS Exercises on Soccer Database
Next SQL Exercise: Number of goals scored by each team in each match.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
How to drop all tables from a database with one SQL query?
USE Databasename SELECT 'DROP TABLE [' + name + '];' FROM sys.tables
Ref: https://bit.ly/3PIUmPL
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
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