Grokking SQL for Tech Interviews

0% completed

Types of Subqueries

Subqueries can be categorized based on where they appear in an SQL statement and their purpose. They are categorized as,

  1. Nested Scalar Subquery
  2. Single-Row Subquery
  3. Multiple-Row Subquery
  4. Single-Column Subquery
  5. Correlated Subquery

Example Data

The given table will be used for the demonstration of subtypes of nested queries.

1. Nested Scalar Subquery

A Nested Scalar Subquery returns a single value and is often used in a comparison. In this example, we retrieve the student_name where the student_id is the maximum.

Query

SELECT student_name FROM students

.....

.....

.....

Like the course? Get enrolled and start learning!