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 theId
column of thePlayers
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 theId
column of theTeams
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 1400+ tech skills courses.