SQL Tutorial for Beginners: Learn SQL Step by Step
What Is SQL?
SQL (Structured Query Language) is the language you use to talk to databases. When you want to pull the top 10 customers from a database of a million, calculate total sales for last quarter, or update every product that's out of stock — SQL is how you do it.
SQL was created in the 1970s at IBM and has outlived every programming language that tried to replace it. Every major database — MySQL, PostgreSQL, SQL Server, Oracle, SQLite — speaks SQL. Learn it once, and you can work with any of them.
Why Learn SQL in 2026?
Three reasons, in order of how practical they are:
- It's on every data job posting. Data analyst, data engineer, business intelligence developer, product analyst, marketing analyst — SQL is the non-negotiable first skill for all of them.
- It pays well for the effort. A week of focused learning gets you to "job-ready" for entry-level data roles that start around $55–70k in the US.
- It ages well. The SQL you learn today will still work in 2040. The Python library you just learned probably won't.
What You'll Learn in This Tutorial
This is a 21-chapter course covering:
- Querying data — SELECT, WHERE, ORDER BY, LIMIT
- Combining tables — INNER JOIN, LEFT JOIN, UNION
- Aggregating data — COUNT, SUM, AVG, GROUP BY, HAVING
- Changing data — INSERT, UPDATE, DELETE
- Designing databases — CREATE TABLE, primary keys, indexes, views
- Advanced topics — subqueries, transactions, stored procedures, PL/SQL, Transact-SQL
By the end, you'll be able to read any SQL query in the wild, write the queries you need for data analysis or app development, and know which features of each database flavor to watch for.
Prerequisites
None. You don't need to know Python, JavaScript, or any other language. You don't need to understand databases yet — we'll cover that. You just need a browser and about 15 hours of total time spread however works for you.
How to Practice SQL Without Installing Anything
Before you read another chapter, open one of these in a new tab. You'll want to run the queries in this page and the later chapters:
- SQLite Online — instant in-browser SQL sandbox, no signup
- DB Fiddle — supports MySQL, PostgreSQL, SQLite, SQL Server
- SQLZoo — pre-loaded with practice databases
All three are free. Pick one and leave it open in a tab.
A Quick Look at a Database
A database is a collection of tables. A table is just rows and columns — like a spreadsheet, but with rules. Here's a tiny example database we'll use throughout this tutorial.
Table: customers
| id | name | city | country | signup_date |
|---|---|---|---|---|
| 1 | Alice Chen | Paris | France | 2024-03-15 |
| 2 | Bob Martinez | Madrid | Spain | 2024-06-22 |
| 3 | Carla Rossi | Rome | Italy | 2025-01-08 |
| 4 | David Kim | Paris | France | 2025-04-30 |
| 5 | Elena Popescu | Bucharest | Romania | 2025-11-12 |
Table: orders
| id | customer_id | product | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | Laptop | 1200 | 2024-04-02 |
| 102 | 2 | Headphones | 89 | 2024-07-18 |
| 103 | 1 | Monitor | 350 | 2025-02-09 |
| 104 | 4 | Keyboard | 120 | 2025-05-11 |
| 105 | 3 | Laptop | 1450 | 2025-06-25 |
Two tables, ten rows, five columns each. Every example in this tutorial uses these two tables so you always know what you're looking at.
Your First SQL Query
Here's the simplest useful SQL statement:
SELECT * FROM customers;
Three words. It means "give me every column (*) from the customers table." The result is the entire customers table shown above.
Now let's make it useful — only show names and cities:
SELECT name, city FROM customers;
Result:
| name | city |
|---|---|
| Alice Chen | Paris |
| Bob Martinez | Madrid |
| Carla Rossi | Rome |
| David Kim | Paris |
| Elena Popescu | Bucharest |
SELECT and FROM are traditionally written in uppercase to stand out. SQL itself doesn't care — select and SELECT are identical. Pick a style and stick with it.
Filtering Rows with WHERE
You almost never want all rows. Use WHERE to filter:
SELECT name, city FROM customers WHERE country = 'France';
Result:
| name | city |
|---|---|
| Alice Chen | Paris |
| David Kim | Paris |
You can combine conditions with AND and OR:
SELECT name FROM customers WHERE country = 'France' AND signup_date > '2025-01-01';
That returns just David Kim — the only French customer who signed up in 2025.
Sorting Results with ORDER BY
SELECT name, signup_date FROM customers ORDER BY signup_date DESC;
DESC means newest first. Leave it off (or write ASC) for oldest first.
Limiting Results
Only want the top 3? Add LIMIT:
SELECT name, signup_date FROM customers ORDER BY signup_date DESC LIMIT 3;
TOP instead of LIMIT (SELECT TOP 3 ...). Oracle historically uses ROWNUM. PostgreSQL, MySQL, and SQLite all use LIMIT.
Joining Two Tables
Here's where SQL gets powerful. We have customers and orders in separate tables. To see which customer placed each order, we JOIN them:
SELECT customers.name, orders.product, orders.amount FROM customers INNER JOIN orders ON customers.id = orders.customer_id;
Result:
| name | product | amount |
|---|---|---|
| Alice Chen | Laptop | 1200 |
| Bob Martinez | Headphones | 89 |
| Alice Chen | Monitor | 350 |
| David Kim | Keyboard | 120 |
| Carla Rossi | Laptop | 1450 |
The ON clause is where the magic happens — it tells SQL: "match rows from customers and orders where customers.id equals orders.customer_id."
Notice Elena Popescu isn't in the result — she has no orders. INNER JOIN only returns rows that match in both tables. To include customers with no orders, use LEFT JOIN (we'll cover this in Chapter 6).
Aggregating Data
How much total revenue did each customer generate?
SELECT customers.name, SUM(orders.amount) AS total_spent FROM customers INNER JOIN orders ON customers.id = orders.customer_id GROUP BY customers.name ORDER BY total_spent DESC;
Result:
| name | total_spent |
|---|---|
| Alice Chen | 1550 |
| Carla Rossi | 1450 |
| David Kim | 120 |
| Bob Martinez | 89 |
The GROUP BY is essential — without it, SUM() would add up every row into one total. With it, SQL gives you one sum per customer.
Other useful aggregate functions: COUNT(), AVG(), MIN(), MAX().
Changing Data: INSERT, UPDATE, DELETE
Reading data is only half of SQL. Here's how you change it.
INSERT adds a new row:
INSERT INTO customers (name, city, country, signup_date) VALUES ('Frank Weber', 'Berlin', 'Germany', '2026-04-24');
UPDATE changes existing rows:
UPDATE customers SET city = 'Lyon' WHERE id = 4;
DELETE removes rows:
DELETE FROM customers WHERE id = 5;
WHERE clause with UPDATE and DELETE. Forgetting it updates or deletes every row in the table. Many engineers have a horror story about the day they ran UPDATE users SET password = 'hello' without a WHERE.
Complete Learning Path
Work through these chapters in order. Each builds on the previous one. Estimated time: 30–60 minutes per chapter, 15 hours total.
- Chapter 1 — Introduction to SQL
- Chapter 2 — The SELECT Statement
- Chapter 3 — Expressions, Conditions, and Operators
- Chapter 4 — Functions: Molding the Data You Retrieve
- Chapter 5 — Clauses in SQL
- Chapter 6 — Joining Tables
- Chapter 7 — Subqueries: The Embedded SELECT Statement
- Chapter 8 — Manipulating Data (INSERT, UPDATE, DELETE)
- Chapter 9 — Creating and Maintaining Tables
- Chapter 10 — Creating Views and Indexes
- Chapter 11 — Controlling Transactions
- Chapter 12 — Database Security
- Chapter 13 — Advanced SQL Topics
- Chapter 14 — Dynamic Uses of SQL
- Chapter 15 — Streamlining SQL for Performance
- Chapter 16 — Using Views for the Data Dictionary
- Chapter 17 — Using SQL to Generate SQL
- Chapter 18 — PL/SQL: An Introduction
- Chapter 19 — Transact-SQL: An Introduction
- Chapter 20 — SQL*Plus
- Chapter 21 — Common SQL Mistakes and Fixes
SQL Cheat Sheet
Keep this nearby while you work. Every common statement you'll use in the first month of learning SQL:
| What You Want | SQL Statement |
|---|---|
| Get all data from a table | SELECT * FROM table_name; |
| Get specific columns | SELECT col1, col2 FROM table_name; |
| Filter rows | SELECT * FROM t WHERE col = 'value'; |
| Sort results | SELECT * FROM t ORDER BY col DESC; |
| Limit results | SELECT * FROM t LIMIT 10; |
| Count rows | SELECT COUNT(*) FROM t; |
| Sum values | SELECT SUM(col) FROM t; |
| Group & aggregate | SELECT col, COUNT(*) FROM t GROUP BY col; |
| Join two tables | SELECT * FROM a JOIN b ON a.id = b.a_id; |
| Insert a row | INSERT INTO t (col) VALUES ('val'); |
| Update rows | UPDATE t SET col = 'new' WHERE id = 1; |
| Delete rows | DELETE FROM t WHERE id = 1; |
| Create a table | CREATE TABLE t (id INT, name TEXT); |
| Drop a table | DROP TABLE t; |
Common Beginner Mistakes
These catch almost everyone. Knowing them in advance saves hours.
1. Forgetting WHERE on UPDATE or DELETE
Running DELETE FROM users with no WHERE deletes every user. Always run the SELECT equivalent first to confirm which rows you're about to change, then switch to UPDATE or DELETE.
2. Using = instead of LIKE for partial matches
WHERE name = 'Alice%' looks for the literal string "Alice%". You want WHERE name LIKE 'Alice%' — with LIKE, % is a wildcard.
3. Comparing NULL with = instead of IS NULL
WHERE email = NULL returns no rows ever. Null isn't equal to anything, including itself. Use WHERE email IS NULL.
4. Case sensitivity surprises
In most databases, SQL keywords are case-insensitive but string values are case-sensitive. WHERE country = 'france' won't match 'France'. Use LOWER() or ILIKE (PostgreSQL) for case-insensitive matching.
5. Trying to use WHERE with aggregate functions
WHERE COUNT(*) > 5 fails. For filtering aggregates, use HAVING after GROUP BY: GROUP BY col HAVING COUNT(*) > 5.
Frequently Asked Questions
Is SQL hard to learn for beginners?
No — SQL is one of the easiest programming languages to start with. It reads almost like English (SELECT name FROM customers WHERE city = 'Paris'), there's nothing to install to practice it, and you can run your first useful query within 15 minutes of starting.
How long does it take to learn SQL?
Most beginners can write basic SELECT, WHERE, and ORDER BY queries after 2–3 hours. JOINs and GROUP BY take another few days of practice. Advanced topics like window functions and query optimization take months to master.
Do I need to install anything to learn SQL?
No. You can practice SQL in your browser using free sandboxes like SQLite Online, DB Fiddle, or SQLZoo. For local practice, SQLite is free, requires no setup, and comes pre-installed on macOS and Linux.
What's the difference between SQL and MySQL?
SQL is the language. MySQL is one specific database system that uses SQL. Other databases include PostgreSQL, SQLite, Microsoft SQL Server, and Oracle — they all speak SQL but each has its own dialect with small differences.
Which SQL database should I learn first?
SQLite for learning (zero setup), PostgreSQL for serious work (free, powerful, most in-demand), and Microsoft SQL Server or MySQL if you're targeting specific industry jobs.
Is SQL still worth learning in 2026?
Yes. SQL is still the #1 skill listed in data analyst, data engineer, and backend developer job postings. Despite new tools and AI, SQL remains the universal language for working with relational data — every major database still uses it.
Can I learn SQL without programming experience?
Yes. SQL is declarative — you tell it what you want, not how to get it. That makes it accessible to analysts, marketers, and anyone who works with data without needing to know Python, JavaScript, or any other language first.
How much do SQL developers earn?
Entry-level SQL roles (data analyst) typically start around $55,000–$70,000 in the US. Mid-level SQL-focused roles (data engineer, BI developer) range from $85,000–$130,000. Senior database administrators and architects can earn $140,000+.
Ready to Start?
You now know what SQL is, what you'll learn, and how to practice. You've already seen the six most common query types. Chapter 1 goes deeper on what relational databases actually are and sets you up for everything that follows.
Start Chapter 1: Introduction to SQL →Last updated: April 24, 2026. This tutorial is free and stays free. No signup, no paywall.