w3resource
Soccer Database Exercises

SQL Joins exercises on soccer Database: Find the countries from where the referees managed most of the matches

SQL soccer Database: Joins Exercise-50 with Solution

50. Write a query in SQL to find the countries from where the referees managed most of the matches.

Sample table: match_mast


Sample table: referee_mast


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT country_name,
       count(match_no)
FROM match_mast a
JOIN referee_mast c ON a.referee_id=c.referee_id
JOIN soccer_country b ON c.country_id=b.country_id
GROUP BY country_name
HAVING count(match_no)=
  (SELECT max(mm)
   FROM
     (SELECT count(match_no) mm
      FROM match_mast a
      JOIN referee_mast c ON a.referee_id=c.referee_id
      JOIN soccer_country b ON c.country_id=b.country_id
      GROUP BY country_name) hh);

Sample Output:

 country_name | count
--------------+-------
 England      |     7
(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 referees of each country managed number of matches.
Next: Write a query in SQL to find the referees managed the number of matches.

What is the difficulty level of this exercise?



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