w3resource
Soccer Database Exercises

SQL Joins exercises on soccer Database: Find the position of a player to play who scored own goal

SQL soccer Database: Joins Exercise-58 with Solution

58. Write a query in SQL to find the position of a player to play who scored own goal.

Sample table: goal_details


Sample table: player_mast


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT player_name,
       jersey_no,
       country_name,
       age,
       posi_to_play,
       playing_club
FROM goal_details a
JOIN player_mast b ON a.player_id=b.player_id
JOIN soccer_country c ON a.team_id=c.country_id
WHERE goal_type='O'
ORDER BY player_name;

Sample Output:

    player_name     | jersey_no |    country_name     | age | posi_to_play | pla
ying_club
--------------------+-----------+---------------------+-----+--------------+--------------
 Birkir Saevarsson  |         2 | Iceland             |  31 | DF           | Hammarby
 Ciaran Clark       |         3 | Republic of Ireland |  26 | DF           | Aston Villa
 Gareth McAuley     |         4 | Northern Ireland    |  36 | DF           | West Brom
(3 rows)

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 defender who scored goal for his team.
Next: Write a query in SQL to find the results of penalty shootout matches.

What is the difficulty level of this exercise?



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