w3resource
Soccer Database Exercises

SQL Joins exercises on soccer Database: Find the number of captains who was also the goalkeeper

SQL soccer Database: Joins Exercise-40 with Solution

40. Write a query in SQL to find the number of captains who was also the goalkeeper.

Sample table: match_captain


Sample table: player_mast


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT count(DISTINCT player_name)
FROM match_captain a
JOIN soccer_country b ON a.team_id=b.country_id
JOIN player_mast c ON a.player_captain=c.player_id
AND posi_to_play='GK';

Sample Output:

 count
-------
     4
(1 row)

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 captain who was also the goalkeeper.
Next: Write a query in SQL to find the players along with their team booked number of times in the tournament. Show the result according to the team and number of times booked in descending order.

What is the difficulty level of this exercise?



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