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_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-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.

  1. Level 1: Getting started

    1. Basics: tables, rows, columns 2 exercises
    2. SELECT: query columns 2 exercises
    3. WHERE: filter rows 3 exercises
    4. AND, OR, NOT 3 exercises
    5. IN and BETWEEN 3 exercises
    6. LIKE: pattern matching 3 exercises
    7. NULL and COALESCE 3 exercises
    8. ORDER BY and LIMIT 3 exercises
    9. DISTINCT: drop duplicates 2 exercises
    10. Calculations and column aliases 3 exercises
    11. Project: Customer list 2 exercises
  2. Level 2: Summarizing data

    1. COUNT: count rows 3 exercises
    2. SUM, AVG, MIN, MAX 3 exercises
    3. GROUP BY: summarize groups 3 exercises
    4. HAVING: filter groups 3 exercises
    5. CASE WHEN: conditional logic 3 exercises
    6. String functions 3 exercises
    7. Dates and times 3 exercises
    8. Project: Sales report 2 exercises
  3. Level 3: Joining tables

    1. INNER JOIN: joining tables 3 exercises
    2. LEFT JOIN 3 exercises
    3. Joining multiple tables 3 exercises
    4. Self join 3 exercises
    5. UNION 3 exercises
    6. Subqueries 3 exercises
    7. EXISTS and NOT EXISTS 3 exercises
    8. Project: Order overview 2 exercises
  4. Level 4: Changing data and building tables

    1. INSERT: adding rows 3 exercises
    2. UPDATE: changing rows 3 exercises
    3. DELETE: removing rows 3 exercises
    4. CREATE TABLE 3 exercises
    5. ALTER TABLE 3 exercises
    6. Primary and foreign keys 3 exercises
    7. Views 3 exercises
    8. Transactions 3 exercises
    9. Project: Inventory 2 exercises
  5. Level 5: Advanced queries

    1. WITH (CTE) 3 exercises
    2. Window functions: ROW_NUMBER, RANK 3 exercises
    3. Running totals and shares 3 exercises
    4. LAG and LEAD 3 exercises
    5. Pivot with CASE WHEN 3 exercises
    6. Finding duplicates 3 exercises
    7. Project: Customer analysis 2 exercises
  6. Level 6: Real work and final test

    1. Order of execution 3 exercises
    2. SQL for Excel users 3 exercises
    3. MySQL, PostgreSQL, SQL Server 3 exercises
    4. Project: Monthly report 2 exercises
    5. SQL final testcertificate after levels 1 to 5
  7. Bonus: Database design

    2 lessons, Bonus, not needed for the certificate
    1. Normalization 3 exercises
    2. ER diagrams and table design 3 exercises
  8. Bonus: Performance

    2 lessons, Bonus, not needed for the certificate
    1. Indexes 3 exercises
    2. EXPLAIN: understanding queries 3 exercises
  9. Bonus: Recursive queries and upserts

    2 lessons, Bonus, not needed for the certificate
    1. Recursive queries 3 exercises
    2. UPSERT: insert or update 3 exercises

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.

Write to us

Choose language

Select your preferred language