w3resource

SQL Exercise: Oldest player to have played in a EURO cup 2016 match

SQL soccer Database: Joins Exercise-26 with Solution

26. From the following tables, write a SQL query to find the oldest player to have appeared in a EURO 2016 match. Return country name, player name, jersey number and age.

Sample table: player_mast


Sample table: soccer_country


Sample Solution:

SQL Code:

SELECT a.country_name,b.player_name,b.jersey_no,b.age 
FROM soccer_country a
JOIN player_mast b 
ON a.country_id=b.team_id
WHERE b.age IN (
SELECT MAX(age) 
FROM player_mast);

Sample Output:

    country_name     |  player_name  | jersey_no | age
---------------------+---------------+-----------+-----
 Hungary             | Gabor Kiraly  |         1 |  40
 Republic of Ireland | Shay Given    |        16 |  40
(2 rows)

Code Explanation:

The given query in SQL that selects the name of the country, player name, jersey number, and age of all players who have the maximum age among all players in the player_mast table, and joins the soccer_country table to retrieve the country name for each player based on their team_id.
The JOIN clause joins the tables soccer_country and player_mast based on the country_id and team_id columns.
The WHERE clause selects all rows from the player_mast table where the age is equal to the maximum age in the player_mast table.

Practice Online


Sample Database: soccer

soccer database relationship structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Find the venue that has seen the most goals.
Next SQL Exercise: Two teams that scored three goals in a single game.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.

SQL: Tips of the Day

What is the best way to paginate results in SQL Server?

SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, *
          FROM      Orders
          WHERE     OrderDate >= '1980-01-01'
        ) AS RowConstrainedResult
WHERE   RowNum >= 1
    AND RowNum < 20
ORDER BY RowNum

Database: SQL Server

Ref: https://bit.ly/3MGrNlk

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook