Subqueries
Use subqueries to transform data tables by nesting one query within a query.
StartSubqueries
Lesson 1 of 1
- 1While working with databases, we often need to transform data from one format to achieve a desired result. In SQL, this is often called data transformation or table transformation. We’ll beg…
- 2Nice work! Let’s continue with subqueries. Imagine that you are the head of air traffic control. In our airplanes database, you’d like to know which flights had an origin airport with an elevatio…
- 3Great! The query we just ran is just one kind of subquery, what we refer to as a non-correlated subquery. A non-correlated subquery is a subquery that can be run independently of the outer quer…
- 4The non-correlated subquery examples we’ve used so far utilized two tables (flights and airports), but we can also perform transformations on a single table. For instance, sometimes we need to aggr…
- 5Nice work! We can also write correlated subqueries in SQL. In a correlated subquery, the subquery can not be run independently of the outer query. The order of operations is important in a co…
- 6It would also be interesting to order flights by giving them a sequence number based on time, by carrier. For instance, assuming flight_id increments with each additional flight, we could use the…
- 7Congratulations! You’ve just learned about non-correlated and correlated subqueries in SQL. What can we generalize so far? - Subqueries are used to complete an SQL transformation by nesting o…