Use Cases for Subqueries

Let's look at situations where we might want to use subqueries.

The use of subqueries is not limited to insertion. Subqueries can be used in a variety of scenarios.

The Tournament database

To demonstrate different use cases of subqueries, we’ll use the Tournament database, which consists of these tables:

  • ActionPoints stores points earned by a player for some in-game action:

    • Id: Uniquely identifies each action performed within a game.
    • PlayerId: References the Id column of the Players table.
    • Points: represented the number of points earned.
  • Players stores information about players participating in the game:

    • Id: Uniquely identifies each player.
    • Name: The player name.
    • TeamId: References the Id column of the Teams table and represents the team to which the player belongs.
  • Teams stores information about teams:

    • Id: Uniquely identifies each team.
    • Name: The team name.

Get hands-on with 1200+ tech skills courses.