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(ColumnName)instead.
| Type of count | What is counted |
|---|---|
| COUNT(*) | all rows |
| COUNT(ColumnName) | rows with non-NULL values in ColumnName |
| COUNT(DISTINCT ColumnName) | only the unique values in ColumnName |
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: SupplierID, CompanyName, and ProductsSuppliedCount (the number of products supplied by that company).
Stuck? Here's a hint!
Join the Products and Suppliers tables. Group by two columns: SupplierID and CompanyName.




