Instruction
It's time to wrap things up for this part. First, let's review what we learned:
- SQL reports often require joining a lot of tables.
- Every column listed in the
SELECTstatement that's NOT used with an aggregate function must appear in theGROUP BYclause. - Not every column from the
GROUP BYclause must appear in theSELECTclause. - Watch out when using
COUNT(). - Avoid using
LEFT JOINs withCOUNT(*). UseCOUNT(column_name)instead.
| Type of count | What is counted |
|---|---|
| COUNT(*) | all rows |
| COUNT(column_name) | rows with non-NULL values in column_name |
| COUNT(DISTINCT column_name) | only the unique non-NULL values in column_name |
How about a short quiz before we start the next part?
Exercise
Find the total number of products supplied by each supplier. Show the following columns: supplier_id, company_name, and products_supplied_count (the number of products supplied by that company).
Stuck? Here's a hint!
Join the products and suppliers tables. Group by two columns: supplier_id and company_name.




