Search⌘ K

Use Cases for Subqueries

Explore how to apply subqueries in T-SQL for different scenarios such as filtering data with WHERE clauses, adding related data as separate columns, and using subqueries as data sources. Gain practical understanding by working with example queries from a Tournament database.

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
...