w3resource
Soccer Database Exercises

SQL exercises on soccer Database: Find the player who was the goalkeeper for Italy in penalty shootout against Germany in Football EURO cup 2016

SQL soccer Database: Subqueries Exercise-16 with Solution

16. Write a query in SQL to find the player who was the goalkeeper for Italy in penalty shootout against Germany in Football EURO cup 2016.

Sample table: player_mast


Sample table: penalty_gk


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT player_name 
FROM player_mast 
WHERE player_id=(
SELECT player_gk 
FROM penalty_gk 
WHERE match_no=(
SELECT match_no 
FROM penalty_gk
WHERE team_id=(
SELECT country_id 
FROM soccer_country 
WHERE country_name='Italy') 
OR team_id=(
SELECT country_id 
FROM soccer_country 
WHERE country_name='Germany') 
GROUP BY match_no 
HAVING COUNT(DISTINCT team_id)=2
) 
AND team_id=(
SELECT country_id 
FROM soccer_country 
WHERE country_name='Italy')
);

Sample Output:

    player_name
-------------------
 Gianluigi Buffon
(1 row)

Query Visualization:

Duration:

Query visualization of Find the player who was the goalkeeper for Italy in penalty shootout against Germany in Football EURO cup 2016 - Duration

Rows:

Query visualization of Find the player who was the goalkeeper for Italy in penalty shootout against Germany in Football EURO cup 2016 - Rows

Cost:

Query visualization of Find the player who was the goalkeeper for Italy in penalty shootout against Germany in Football EURO cup 2016 - Cost

Practice Online


Sample Database: soccer

soccer database relationship structure

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

Previous: Write a query in SQL to find the player along with his team and jersey number who scored the first penalty of the tournament.
Next: Write a query in SQL to find the number of Germany scored at the tournament.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming