w3resource
Soccer Database Exercises

SQL Subqueries exercises on soccer Database: Find the player of portugal who taken the 7th kick against poland

SQL soccer Database: Subqueries Exercise-29 with Solution

Write a query in SQL to find the player of portugal who taken the 7th kick against poland.

Sample table: penalty_shootout


Sample table: player_mast


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT a.match_no,
       b.player_name,
       a.kick_no
FROM penalty_shootout a,
     player_mast b
WHERE a.player_id=b.player_id
  AND kick_no=7
  AND match_no=
    (SELECT match_no
     FROM penalty_shootout
     WHERE team_id =
         (SELECT country_id
          FROM soccer_country
          WHERE country_name='Portugal' )
     GROUP BY match_no)
GROUP BY match_no,
         player_name,
         kick_id;

Sample Output:

 match_no | player_name | kick_no
----------+-------------+---------
       45 | Nani        |       7
(1 row)

Query Visualization:

Duration:

Query visualization of Find the player of portugal who taken the 7th kick against poland - Duration

Rows:

Query visualization of Find the player of portugal who taken the 7th kick against poland - Rows

Cost:

Query visualization of Find the player of portugal who taken the 7th kick against poland - Cost

SQL Code Editor:

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 match no. and teams who played the match where highest number of penalty shots had been taken.
Next: Write a query in SQL to find the stage of match where the penalty kick number 23 had been taken.

What is the difficulty level of this exercise?



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