Get startedGet started for free

Getting started with nested subqueries

Time to take your subqueries up a gear! You only have time to watch so much soccer, and want to know if the England Premier League is exciting as people say.

You'll compare the maximum number of goals scored in a single match across each season against the maximum for the England Premier League.

This exercise is part of the course

Data Manipulation in SQL

View Course

Exercise instructions

  • Complete a nested subquery to select the country_id for 'England Premier League' from league, which will be used to filter the parent subquery.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT 
    season,
    MAX(home_goal + away_goal) AS max_goals,
    (SELECT MAX(home_goal + away_goal) 
     FROM match 
     WHERE season = main.season
     -- Subquery to get the max goals in a Premier League match for the same season
     AND country_id IN (____)
    ) AS pl_max_goals
FROM match AS main
GROUP BY season;
Edit and Run Code