From the course: SQL Essential Training

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Subqueries and aggregate functions

Subqueries and aggregate functions - SQL Tutorial

From the course: SQL Essential Training

Start my 1-month free trial

Subqueries and aggregate functions

- Have you ever heard of tree hugging? While a subquery is kind of like that it's one query hugging another. A subquery is simply one query written inside of another. When a query is wrapped inside of another it's called a "Nested query." The wrapping is just an open and closed parenthesis or brackets that surround the query. Let's say we were asked by WSDA management how each individual city was performing against the global average sales? Let's think about that. To respond to this request we would need to display the global average sales amount and at the same time, display the average sales per city, management can then see what cities are on par, over and underperforming. Subqueries are useful in this type of scenario. Instead of writing one query, for instance to get the global average, then another query to get the average sales per city, we can just use a subquery that performs both operations at once.…

Contents