w3resource
Soccer Database Exercises

SQL Joins exercises on soccer Database: Find the players who booked most number of times

SQL soccer Database: Joins Exercise-42 with Solution

42. Write a query in SQL to find the players who booked most number of times.

Sample table: soccer_country


Sample table: player_booked


Sample table: player_mast


Sample Solution:

SQL Code:

SELECT c.player_name,COUNT(b.*) Booked 
FROM soccer_country a
JOIN player_booked b ON a.country_id=b.team_id
JOIN player_mast c ON b.player_id=c.player_id
GROUP BY c.player_name
having COUNT(b.*)=(
SELECT MAX(mm) FROM (
SELECT COUNT(*) mm 
FROM player_booked 
GROUP BY player_id) inner_result);

Sample Output:

    player_name    | booked
-------------------+--------
 NGolo Kante       |      3
 William Carvalho  |      3
 Bartosz Kapustka  |      3
(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 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.
Next: Write a query in SQL to find the number of players booked for each team.

What is the difficulty level of this exercise?



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