SQL Basics

SQL is the language for asking questions of a database. In these lessons you write real queries against a small shop database, see the result as a table, and get each exercise checked instantly.

0 of 9 lessons done
Start Course

Part 1Reading Data

  1. Your First QueryRead data from a table with SELECT and FROM, and choose which columns you want.
  2. Filtering RowsKeep only the rows you need with WHERE, comparison operators, AND and OR.
  3. Sorting and LimitingPut results in order with ORDER BY and return only the top rows with LIMIT.
  4. Searching Text and RangesMatch patterns with LIKE, lists of values with IN and ranges with BETWEEN.

Part 2Summarizing Data

  1. Counting and CalculatingSummarize a table with COUNT, SUM, AVG, MIN and MAX, calculate new columns and name them with AS.
  2. GroupingCalculate totals and counts per category with GROUP BY, and filter the groups with HAVING.

Part 3Working With Several Tables

  1. Joining TablesCombine rows from related tables with JOIN and ON, and use table names to say which column you mean.
  2. Changing DataAdd rows with INSERT, change them with UPDATE and remove them with DELETE.
  3. Project: A Sales ReportCombine joins, calculations, grouping and sorting to find the shop's best customers.

Your Certificate

Finish every lesson in this course to unlock a certificate with your name on it.

What you will learn

Almost every app and website keeps its data in a database, and SQL (often said "sequel") is how you get it back out. It is one of the most useful skills for anyone who works with data: analysts, marketers, developers and spreadsheet power users alike.

The practice database

All lessons use the same small database of a shop, with three tables: customers, products and orders. It runs inside your browser using SQLite, the most widely used database engine in the world. Every time you press Run you get a fresh copy, so you can experiment freely.

How the lessons work

Type a query and press Run (or Ctrl+Enter) to see the rows it returns. Check My Code compares your result with the expected one, so any query that returns the right rows passes. You can practice more in the Code Playground, which has the same database.

Frequently asked questions

Is this SQL course free?

Yes. Every lesson is free, with no account and no limits.

Do I need to install a database?

No. A real SQLite database runs inside the page. The first run downloads the engine, which is under 1 MB.

Which kind of SQL is taught?

The lessons use SQLite and stick to standard SQL that also works in MySQL, PostgreSQL and SQL Server. Small differences between databases mostly show up in advanced features.

Can I break the practice database?

No. Each run starts from a fresh copy, so deleting or changing rows only lasts for that run.

How are my answers checked?

Your query result is compared with the expected rows. There is usually more than one correct way to write a query, and all of them pass.

Do I get a certificate?

Yes. Finish every lesson to unlock a certificate of completion with your name on it. It is a personal record, not an accredited qualification.