Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Providing detailed information and counting objects
Calculating metrics for multiple business objects
Understanding the difference between various count metrics
14. Summary


It's time to wrap things up for this part. First, let's review what we learned:

  1. SQL reports often require joining a lot of tables.
  2. Every column listed in the SELECT statement that's NOT used with an aggregate function must appear in the GROUP BY clause.
  3. Not every column from the GROUP BY clause must appear in the SELECT clause.
  4. Watch out when using COUNT().
  5. 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
  6. Avoid using LEFT JOINs with COUNT(*). Use COUNT(column_name) instead.

How about a short quiz before we start the next part?


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). Show also suppliers that supply no products.

Stuck? Here's a hint!

Join the products and suppliers tables. Group by two columns: supplier_id and company_name. Use LEFT JOIN or RIGHT JOIN, and COUNT(product_id).