Data & Analytics

SQL & Database Fundamentals

Tables, queries, filters, and joins for data that already exists.

★★★★★4.7 · Based on 69 learners64 lessons · 16 hr

SQL & Database Fundamentals teaches you to ask a database a precise question. You will create a small set of tables, filter rows, and join related data. The lectures use standard SQL so the ideas survive a change of tool.

Course syllabus

  1. 01. Tables

    • Rows, columns, and keys

      What a table is for, and how a row is identified.

      15 min
    • A table is one kind of thing

      Customers in one table, orders in another.

      17 min
    • A primary key

      The column that makes a row unique.

      13 min
    • A foreign key

      A column that points at a row in another table.

      16 min
    • Create a small customers table

      An id, a name, and a city. Nothing extra yet.

      18 min
    • Create an orders table

      An id, the customer id, a date, and an amount.

      14 min
    • Insert rows you can remember

      Three customers and five orders you could retype.

      18 min
    • Look at the table before you query it

      The rows, so a later result can surprise you honestly.

      12 min
  2. 02. Select

    • SELECT and WHERE

      Ask for the columns and rows you mean.

      17 min
    • Choose the columns

      Name them. A star is for looking, not for a query you will keep.

      15 min
    • Filter with WHERE

      The condition that throws the other rows away.

      16 min
    • Compare a number

      Greater than, less than, and equal, on the amount.

      13 min
    • Compare text

      A city, and the quotes that make it text.

      15 min
    • AND and OR

      Both conditions, or either. Parentheses when you mix them.

      17 min
    • NULL is not a value you compare with equals

      IS NULL, when the cell was never filled.

      13 min
    • A filter you can say in a sentence

      Orders over 500 from this year. Then write only that.

      16 min
  3. 03. Sort and totals

    • Sort, limit, and aggregate

      Order, counts, and totals.

      18 min
    • ORDER BY

      The column, and whether large values come first.

      14 min
    • LIMIT the preview

      The first ten rows when you are still exploring.

      18 min
    • COUNT the rows

      How many orders match the filter.

      12 min
    • SUM and AVG

      The total and the average, and the column they apply to.

      17 min
    • GROUP BY a category

      One result row per city, or per customer.

      15 min
    • WHERE before the group, HAVING after

      Filter rows first. Filter groups second.

      16 min
    • A total you can check by hand

      Five orders. Add them yourself. Then trust the query.

      13 min
  4. 04. Joins

    • Joins

      Combine two tables without duplicating the story.

      15 min
    • Why you join

      The customer name lives in another table. The order only has the id.

      17 min
    • INNER JOIN

      Rows that have a match on both sides.

      13 min
    • The ON clause is the key

      orders.customer_id = customers.id. Not a guess.

      16 min
    • A join that multiplies rows

      If the key is wrong, five orders become twenty.

      18 min
    • LEFT JOIN

      Every order, even when the customer row is missing.

      14 min
    • Select columns from both tables

      Prefix the names so city is not ambiguous.

      18 min
    • Read the join before the filter

      Who is kept, then which of those you still want.

      12 min
  5. 05. Three tables

    • A products table

      An id and a name. The order line will point at it.

      17 min
    • An order line

      The order, the product, and the quantity. A third table with a job.

      15 min
    • Join line to product

      The name of the thing that was sold.

      16 min
    • Join line to order to customer

      Who bought it, on which order.

      13 min
    • A sum across the line items

      Quantity times price, grouped by order.

      15 min
    • Do not join a table you do not need

      Extra tables are how totals quietly double.

      17 min
    • Alias a table

      A short name so the query can be read.

      13 min
    • Draw the three boxes

      Lines, orders, customers. Arrows on the keys.

      16 min
  6. 06. Change data carefully

    • INSERT a row with named columns

      The columns and the values, in the same order.

      18 min
    • UPDATE with a WHERE

      Change one customer. Never practise an update without a filter.

      14 min
    • See the rows before you update them

      SELECT with the same WHERE first.

      17 min
    • DELETE is not undo

      A WHERE you have already SELECTed.

      11 min
    • A transaction in plain words

      Several changes that should all succeed, or none of them.

      16 min
    • Why this course stays on SELECT

      Reading is the skill. Writing comes after you can see the rows.

      14 min
    • A backup thought

      On a real database, someone else owns the delete key.

      15 min
    • Your practice database is disposable

      You can drop it. You cannot drop a client's.

      12 min
  7. 07. Read a query

    • Reading a query you did not write

      Find the filters and the join before you trust the result.

      14 min
    • Start at FROM

      The tables. Everything else hangs off them.

      16 min
    • Then the joins

      Which keys, and whether an inner join dropped rows.

      12 min
    • Then WHERE

      The rows that remain.

      15 min
    • Then GROUP BY and the select list

      What one result row represents.

      18 min
    • A subquery you can name

      If the inner query has a job, say the job.

      13 min
    • Format it so the eye can land

      Each clause on its own line.

      17 min
    • The question the query claims to answer

      If you cannot say it, do not ship the number.

      11 min
  8. 08. A small report

    • The question

      Which customers spent the most this month.

      16 min
    • The tables you need

      Customers and orders. Not products, unless the question asks.

      14 min
    • The filter on the date

      This month, written so next month you know what to change.

      15 min
    • The group and the sort

      One row per customer, largest total first.

      12 min
    • Limit to ten

      A list someone will read.

      14 min
    • Check two customers by hand

      Their orders, added, match the query.

      16 min
    • Save the query with a name

      A file called top-customers, not query3.

      12 min
    • What you would add if they asked why

      The orders under the total, as a second query, not a guess.

      15 min

Lecture videos stay with the course. Playback for enrolled students will open once payments are available. Video links are not published on this page.