A subquery in SQL is a query nested inside another SQL query. It allows complex filtering, aggregation and data manipulation by using the result of one query inside another. They are an essential tool when we need to perform operations like:

  • Filter rows based on results from another query.
  • Apply aggregate functions like SUM, COUNT, or AVG dynamically.
  • Update data using values from other tables.
  • Delete rows based on conditions returned by another query.