SQL subqueries are like little helpers that fetch data for our main query. They’re super handy when we need to filter our results based on some other data in our database.
Probably the most common placement of a subquery in SQL is in the WHERE
clause. Placing a subquery in the WHERE
clause allows us to compare a column against a set of rows that match a certain criteria.
Let’s look at three quick examples of subqueries in the WHERE
clause.