What is a Subquery


A subquery is a query written inside another SQL query.

It is also known as a nested query.

Subqueries allow SQL to perform complex operations step by step.

The inner query runs first.

The result of the inner query is then used by the outer query.

This makes SQL very powerful for advanced logic.

Subqueries are commonly used to compare values, filter records, and calculate results.

They are widely used in real-world backend systems.

A subquery can return a single value or multiple values.

The outer query depends on the subquery result.

This creates nested logic inside SQL.

Subqueries make SQL flexible and powerful.

They are often asked in technical interviews.

Understanding subqueries is essential for advanced SQL development.