SQL for beginners: learn SQL by writing real queries
A step-by-step path for complete beginners, from your very first query to reports across several tables. You type every query yourself against a real database in your browser and get feedback the moment you check it. Nothing to install, and level 1 is free.
Try it now
This is what an exercise looks like. The database belongs to a small online shop for office supplies, and the table you need is shown above the editor. Never written SQL before? The hints take you to the answer in three steps.
How it works: after SELECT come the columns you want to see, separated by commas, after FROM the table. SELECT name FROM customers, for example, shows only the names of all customers.
Task Sales needs a list of all customers and where they are. From the customers table, get the columns name and city, in that order.
customers 12 rows, 7 columns
| customer_id | name | city | country | customer_since | segment | phone |
|---|---|---|---|---|---|---|
| 1 | Harbor Fremont Partners | Boston | USA | 2021-03-15 | Business | 617-555-0142 |
| 2 | Emily Carter | Chicago | USA | 2022-07-01 | Consumer | NULL |
| 3 | Riverside County Office | Riverside | USA | 2020-11-20 | Government | 951-555-0110 |
| 4 | Raj Patel | Leeds | UK | 2023-01-09 | Consumer | 0113 496 0123 |
| 5 | Lakeview Hotel Ltd | Manchester | UK | 2022-04-18 | Business | 0161 496 0456 |
| 6 | Olivia Brooks | Austin | USA | 2024-02-27 | Consumer | NULL |
| 7 | Greene & Shaw LLP | London | UK | 2021-09-05 | Business | 020 7946 0321 |
| 8 | Maple Grove High School | Austin | USA | 2023-08-14 | School | 512-555-0187 |
| 9 | Chloe Evans | Boston | USA | 2025-05-30 | Consumer | 617-555-0199 |
| 10 | Northline Printing Co | Toronto | Canada | 2020-06-12 | Business | 416-555-0133 |
| 11 | Daniel Kim | Seattle | USA | 2024-10-03 | Consumer | NULL |
| 12 | Westbrook Dental Clinic | Chicago | USA | 2022-12-01 | Business | 312-555-0164 |
Done? Then you already know how SELECT and FROM work together. Lesson 1 explains what tables, columns and primary keys really are.
Start with lesson 1 Create a free account
What you will learn
SQL is the language for getting answers out of databases. The course has six levels, and each one ends with a project where you put the new skills to work on a bigger task.
- Level 1: Getting started. How tables work, choosing columns with SELECT, filtering rows with WHERE, AND, OR, IN, BETWEEN and LIKE, handling missing values (NULL), sorting with ORDER BY, removing duplicates with DISTINCT and calculating new columns.
- Level 2: Summarizing data. Counts, totals and averages, groups with GROUP BY and HAVING, conditional logic with CASE, text and date functions.
- Level 3: Joining tables. Combining orders with customers and products using JOIN and LEFT JOIN, plus UNION and subqueries.
- Level 4: Changing data and building tables. INSERT, UPDATE and DELETE, your own tables with primary and foreign keys, views and transactions.
- Level 5: Advanced queries. Readable queries with WITH, rankings and running totals with window functions, finding duplicates.
- Level 6: Real work and final test. The order in which the database actually runs a query, SQL for Excel users and how MySQL, PostgreSQL and SQL Server differ, followed by the last project and the final test with a certificate.
The learning path
Each lesson builds on the one before, but you can open any of them directly if you already know a topic. A free account keeps track of the exercises you have solved. Once you have completed level 5, you can take the final test and earn a certificate with a verification link. If you want to use SQL in a specific job, three intensive courses follow: data analysis, finance and marketing.
-
Level 1: Getting started
-
Level 2: Summarizing data
-
Level 3: Joining tables
-
Level 4: Changing data and building tables
-
Level 5: Advanced queries
-
Level 6: Real work and final test
-
Bonus: Database design
-
Bonus: Performance
-
Bonus: Recursive queries and upserts
How practicing in the browser works
Every exercise runs on a real SQL database (SQLite), not a simulation. Type your query and press Run (or Ctrl+Enter) to see the result table straight away, as often as you like. Tap table and column names to insert them. Each query starts from a fresh copy of the data, so you cannot break anything.
Check compares your result with the task: columns, rows and values. What counts is the output, not whether your query matches the sample solution word for word. Then the exercise runs your query once more against different, hidden data. Copying the result or typing a value straight into the query gets caught there. If something is off, the message tells you what: one column too many, the wrong order, a stray comma before FROM, or a misspelled column name along with the correct one.
Hints come in three steps, from the idea to an almost finished query. The solution only appears if you ask for it.
Who this course is for
- Office and admin roles: you want to pull lists straight from your inventory, CRM or accounting system instead of waiting for an export.
- Finance, reporting and sales: you analyze revenue, customers and orders and want numbers faster and with a trail you can follow.
- Job seekers: the posting asks for SQL skills and you want to list them on your resume with confidence. For the interview itself, practise with SQL 50, 50 interview-style questions. Facing an online test? See how to prepare for HackerRank SQL.
- Business analysts: you check requirements against the data, define KPIs and reconcile systems. What you need for that: SQL for business analysts.
- Excel users: you know filters, VLOOKUP and SUMIF. In SQL the same ideas are called WHERE, JOIN and GROUP BY, so a lot will feel familiar. The Excel course is here too.
- Teams: companies, schools and public bodies can buy team seats with one shared join link.
What is free and what needs Premium
Every lesson is free to read. All of level 1, including every exercise and the project, is free. From level 2 on, the first exercise in each lesson is free; the remaining exercises and the level projects are part of Premium. One Premium plan covers every subject on LearnThisNext, today Excel, SQL, VBA and Power BI. See pricing for the current price.
SQL, MySQL, PostgreSQL: which one am I learning?
SQL is the language. MySQL, PostgreSQL, Microsoft SQL Server and SQLite are database systems that speak it. SQL is an international standard (ISO/IEC 9075), so the core is shared: a query with SELECT, WHERE, GROUP BY and JOIN that you write here looks the same or nearly the same in all of them. Where the systems differ, each lesson says so. One page per system sums up the differences: MySQL, PostgreSQL, SQL Server and Oracle SQL, plus the Oracle SQL certification (1Z0-071) mapped to our lessons.
FAQ
How long does it take to learn SQL?
It depends on how much time you put in and what you need it for. Level 1 has ten lessons and a project; after it you can pull, filter and sort lists from a database on your own. Reports across several tables need levels 2 and 3 as well. Short, regular practice where you write every query yourself beats long sessions of reading.
Do I need to install anything?
No. Everything runs in your browser, on a phone as well. You do not need MySQL or any other software.
Should I learn SQL or MySQL?
SQL. MySQL is one of several database systems that use SQL. Once you know SQL, you will find your way around MySQL, PostgreSQL or SQL Server quickly, because the differences are mostly details such as data types, individual functions or how names are quoted.
Can I learn SQL for free?
Yes, to get started. Level 1 with all its exercises is free, and you can read every lesson for free. From level 2 on, the first exercise of each lesson is free too; the other exercises need Premium.
Do I need coding experience?
No. SQL is a query language: you describe the result you want rather than telling the computer how to get it. The keywords are English words, and there are not many of them.
I already know some SQL. Do I have to start at lesson 1?
No. Open any lesson directly. If you solve its exercises right away, you are through in a few minutes. The SELECT lesson is a good place to test yourself.