How this course works
SQL is the language of databases, and the only way to learn it is to write it. So every lesson here is built around a small practice database, a made-up shop with customers, products, orders and staff, and everything you read can be run.
- Read a lesson. Each one covers a single idea, such as
WHEREorGROUP BY, with examples and their real results. - Press Try it under an example. The query opens in the practice box. Change a word or a number, press Run, and see what happens. You cannot break anything. One button puts the database back as new.
- Do the exercises. Each lesson ends with three. Write your query in the practice box and press Check my answer. The box compares your rows with ours and tells you whether they match.
- Mark the lesson as done. A tick appears beside it on this page. The ticks are kept in your own browser.
The lessons are in order, and each uses only what came before. If you are new, start at lesson 1. If you know some SQL, the list below shows where to jump in.
What you will be able to do
- Read data from a table and pick the rows and columns you want.
- Sort, limit and summarise: counts, totals and averages for each group.
- Join several tables and find what is missing from one of them.
- Add, change and remove data without accidents.
- Create tables with sensible types, keys and rules.
- Use
CASE, dates, views,WITHand window functions, which is where reports get interesting.
That covers what is asked of most people who use SQL at work: analysts, accountants who report from a database, testers, support staff and new developers. The page of interview questions gathers the questions that come up again and again.
What you need
A browser. The practice box runs a real database engine, SQLite, inside the page. Your queries do not leave your phone or computer. It works on a phone, though a keyboard makes longer queries easier.
Which database is this for?
All of them. The core of SQL is the same in MySQL, PostgreSQL, SQL Server, Oracle and SQLite. Where they differ, for example in how to take the first ten rows or how to work with dates, the lesson shows each form, and the page on SQL in different databases puts the differences in one place.
Questions people ask
Is SQL hard to learn?
It is one of the easier computer languages. A query reads almost like an English sentence, and you can do useful things after the first three lessons. Joins and grouping take some practice. Most people are comfortable with the first eighteen lessons within two or three weeks of short daily sessions.
Do I need to know programming first?
No. SQL is not like a general programming language. You describe the result you want, and the database works out how to get it. Many people who use SQL every day never learn another language.
Is SQL still worth learning?
Yes. It has been the standard way to work with data for about fifty years and is still the most widely requested data skill. Spreadsheets run out of room. Databases do not, and SQL is how you talk to them.
Can I use the practice box for my own tables?
Yes. You can create tables and insert rows of your own, as lessons 19 to 22 show. They live in your browser tab until you press Reset or close the page.
This is an independent learning site. It is not connected with the makers of any database product. MySQL, PostgreSQL, SQL Server, Oracle and SQLite are named only so that you know where a piece of SQL works. The shop, its customers and its staff in the practice database are made up.