Subqueries
Let one query work out the number the other one needs
0 of 3 done · Lesson 8 of 8
Understand
Somebody asks which orders are bigger than average. You know how to get the average and you know how to filter, and the problem is that you need the first answer before you can write the second. Working it out, reading the number and typing it into the next query gives you an answer that is right this morning and wrong by Friday. A subquery is that first query in brackets, run for you every time.
SELECT which_columns_you_want FROM where_it_lives WHERE a_column > (SELECT one_value FROM where_it_lives);
SELECTwhich columns you wantFROMwhich tableWHEREwhich rows to keepINmatch against a list
The tables you are working with
8 rows
| id | customer | region | amount |
|---|---|---|---|
| 3101 | Northwind | Otago | 1250 |
| 3102 | Kea Ltd | Waikato | 620 |
| 3103 | Halcyon | Otago | 2110 |
| 3104 | Brightsmith | Auckland | 480 |
4 more rows in the table. Your query sees all 8.