Free SQL Book: Simplify SQL for Absolute Beginners

  • Free: Chapters 1–3 as a PDF and an EPUB
  • Every example runs on ShopDB, a free practice database
  • MySQL and SQL Server side by side
  • Real query results you can check row by row
  • Practice questions with answers after every chapter

I wrote this book for the person I was when I started: someone who could use a spreadsheet, had heard that SQL was important, and didn’t know where to begin. It takes the beginner articles on this site, puts them in the right order, and builds every lesson on one practice database, so you never have to wonder what data to type your queries against.

The full book will have 23 chapters. The first three are ready, and you can have them free: read Chapter 1 below, or download Chapters 1–3 as a PDF or EPUB.

Get the free book (PDF + EPUB)

Enter your email and the download buttons appear right here. You’ll also get the new chapters as they’re finished, and one short email when a new tutorial goes live. No spam; unsubscribe any time.

Thank you! Your downloads:

The EPUB is inside a zip file: unzip it, then open it in Apple Books, Google Play Books or Calibre, or send it to your Kindle with Amazon’s Send to Kindle. You’ll also need the free ShopDB scripts.

We only use your email to send SimplifyDatabase updates. See our Privacy Policy.

What’s inside

In the free preview (Chapters 1–3):

  • Chapter 1: What a Database Is (and Why Not Excel). Tables, rows, keys, SQL, and when a spreadsheet stops being enough.
  • Chapter 2: Set Up Your Practice Database. Install MySQL or SQL Server for free, load ShopDB and run your first query.
  • Chapter 3: SELECT, WHERE, ORDER BY and LIMIT. Filter, sort and take the top rows, plus the three traps that catch everyone.
  • Appendix C: answers to every practice question.

Coming in the full book: DISTINCT and aliases, LIKE/IN/BETWEEN, NULL, CASE, GROUP BY and HAVING, keys and JOINs, SELF JOIN, UNION, subqueries and CTEs, data types and constraints, INSERT/UPDATE/DELETE, transactions, normalization, string and date functions, window functions, a final project and 25 interview questions.

Read Chapter 1 online: What a Database Is (and Why Not Excel)

In this chapter

  • What a database is, in plain words
  • Why a growing business moves from a notebook to a spreadsheet to a database
  • How tables, rows, columns and keys fit together
  • The difference between a database and a DBMS
  • When Excel is the right tool, and when SQL is

Every time you check your bank balance, order something online or look up a contact on your phone, a database answers you. You never see it, but it’s there, quietly storing information and handing back exactly the piece you asked for.

This chapter explains what a database is in plain language, using one small shop as the example from start to finish: ShopDB, the practice database you’ll use for the rest of the book. You don’t need any technical background. By the end, you’ll know the words people use (tables, rows, keys, SQL), and you’ll be ready to set up your own copy in Chapter 2.

In one sentence: A database is an organised collection of information, stored on a computer so it can be searched, updated and shared quickly and safely. Most databases keep their data in tables made of rows and columns, and you talk to them with a language called SQL.

A database in everyday life

The contacts list on your phone is a tiny database. Each contact has the same kinds of information (a name, a number, maybe an email), and you can find “Ahmed” in a second even if you have 500 contacts. You don’t scroll through all of them. You search, and the phone finds him for you.

A real database does the same thing on a much bigger scale: millions of records, many people using it at the same time, and rules that stop the information from becoming a mess.

From a notebook to a database: a small shop’s story

ShopDB belongs to a small online electronics shop in Manama. It sells laptops, phones, monitors and the cables and mice that go with them. Here’s how its records grew up.

Stage 1: the notebook

At first, the owner wrote every order in a notebook: the date, the customer, what they bought and the price. It worked for a few weeks. Then she wanted to know how many USB-C cables she sold last month, and she spent an evening counting by hand.

Stage 2: the spreadsheet

So she moved to Excel. Now she could sort and add up totals in seconds. Much better. But as the shop grew, new problems appeared:

  • The same customer was typed three different ways (“Sara Ahmed”, “S. Ahmed”, “sara ahmed”), so reports counted her as three people.
  • Her assistant opened an older copy of the file, added orders to it, and now there were two versions of the truth.
  • Someone typed “two” in the quantity column, and the monthly total broke.
  • The file got big and slow, and one day it wouldn’t open.

Stage 3: the database

Finally, the shop moved its records into a database. Each customer is stored once. The quantity column only accepts numbers. Two people can record orders at the same time without overwriting each other. And “how many USB-C cables did we sell last month?” is answered in a moment, even after years of orders.

That’s really what a database is for: keeping information correct, shared and fast to find as it grows.

How a database organises data

Most databases you’ll meet are relational databases. They store data in tables, which look a lot like spreadsheet sheets:

  • Each column is one kind of information, like a name or a price. Every value in a column has the same type: all numbers, all dates, or all text.
  • Each row is one record: one customer, one product, one order.

Here are the first rows of ShopDB’s Customers table:

Table Customers (15 rows, first 3 shown):

CustomerID FirstName LastName Phone City
1 Ali Hassan +973 3300 1001 Manama
2 Sara Ahmed +966 50 200 2002 Riyadh
3 Omar Khalid NULL Dubai

And here are the first rows of the Orders table:

Table Orders (48 rows, first 6 shown):

OrderID CustomerID OrderDate
1001 2 2025-01-08
1002 2 2025-01-17
1003 2 2025-01-31
1004 5 2025-03-25
1005 6 2025-03-29
1006 1 2025-04-07

Notice that the Orders table doesn’t repeat Sara’s name and phone. It just stores her number, CustomerID = 2. That number links each order to the right customer. If Sara changes her phone number, you update one row in Customers, and every order still points to the correct, up-to-date person.

(Omar’s phone says NULL. That’s how a database writes “no value here”. You’ll meet NULL many times in this book.)

This idea of separate tables connected by numbers is where the word relational comes from. The tables are related to each other.

The words you’ll hear most

Database people use a handful of words all the time. Here they are in plain English:

Word What it means In ShopDB
Table A set of records of the same kind Customers, Orders, Products
Row (record) One item in a table Ali’s customer details
Column (field) One kind of information Phone
Primary key A column that identifies each row uniquely CustomerID in Customers
Foreign key A column that points to a row in another table CustomerID in Orders
Query A question you ask the database “Show Ali’s orders”
SQL The language you write queries in SELECT ... FROM Orders
DBMS The software that runs the database SQL Server, MySQL, PostgreSQL

The two kinds of key get a whole chapter of their own: Chapter 10.

Database vs DBMS: a common mix-up

People often say “MySQL is a database”. Strictly speaking, MySQL is a database management system (DBMS): the program that stores the data, checks the rules and answers your questions. The database is the data itself: the shop’s customers, products and orders.

Think of a music player and your playlist. The player is the software (the DBMS). The playlist is your data (the database). One DBMS can look after many databases at the same time. In everyday conversation people use the two words loosely, and that’s fine, but knowing the difference makes documentation much easier to read.

The most common DBMSs are:

  • Microsoft SQL Server: very common in companies, especially with Windows and Microsoft tools.
  • MySQL (and its close cousin MariaDB): popular for websites.
  • PostgreSQL: free, powerful and growing fast.
  • SQLite: a tiny database inside a single file, used in phones and small apps.

This book shows every example in MySQL and SQL Server. Chapter 2 helps you install one of them.

How do you talk to a database? With SQL

You don’t open a database and scroll through it like a spreadsheet. You ask it questions in a language called SQL (Structured Query Language). Here’s the shop owner asking for Ali’s orders:

SELECT OrderID, OrderDate, Status
FROM Orders
WHERE CustomerID = 1;

Result:

OrderID OrderDate Status
1006 2025-04-07 Delivered
1009 2025-04-21 Delivered
1029 2026-01-13 Delivered
1040 2026-04-23 Delivered

Read it out loud: “select the order ID, date and status from Orders where the customer is number 1.” That’s SQL. It reads almost like English, which is why it’s one of the easiest technical skills to start with. The same query works in SQL Server, MySQL and PostgreSQL. You’ll write it yourself in Chapter 3.

SQL and Excel: different jobs

If you work with data, you almost certainly use Excel. It’s on every office computer, everyone understands it, and you can get an answer in a few clicks. So it’s fair to ask: what can SQL do that Excel can’t?

I work with finance and operations teams who live in Excel, and I write SQL every day, so I see both sides. Here’s the main difference in one sentence: in Excel, you do the work (click, filter, drag formulas, copy and paste); in SQL, you describe the result you want, and the database does the work for you, on ten rows or ten million, as many times as you like.

Excel Database + SQL
Best for Small data, hands-on analysis, charts Growing or shared data, repeatable reports
Size Up to about 1 million rows per sheet, slow well before that Millions of rows are normal
Linking lists VLOOKUP / XLOOKUP, which break quietly JOIN on keys (Chapter 11)
Rules Anyone can type anything in any cell Columns accept only the right type; rules stop bad data
Many users Copies and conflicts Built for it
Repeating a report Repeat the clicks Run the same query again

Excel is the right tool for a household budget, a list of class grades or a one-off price comparison. Anything a business depends on every day, with several people entering data, belongs in a database.

The same task, both ways

Say you want ShopDB’s number of customers per country, biggest first.

In Excel: open the file and wait for it to load, insert a PivotTable, drag Country to Rows and CustomerID to Values, make sure it says Count, then sort the column from largest to smallest. It works. But next month, with new customers, you do it all again, and you need to be sure everyone has the latest file.

In SQL:

SELECT Country, COUNT(*) AS Customers
FROM Customers
GROUP BY Country
ORDER BY Customers DESC, Country;

Result (11 rows, first 3 shown):

Country Customers
Bahrain 3
Saudi Arabia 2
UK 2

Four lines. Next month you run exactly the same query, and the new customers are included automatically. Chapter 8 explains every word of it.

From Excel to SQL

If you already know Excel, you know more SQL ideas than you think:

In Excel you… In SQL you write… Chapter
Pick some columns to show SELECT FirstName, City FROM Customers 3
Use a filter WHERE Country = 'Bahrain' 3
Sort a column ORDER BY UnitPrice DESC 3
Remove duplicates SELECT DISTINCT Country 4
Use an IF formula CASE WHEN ... THEN ... END 7
Build a pivot table GROUP BY with SUM, COUNT or AVG 8
Use VLOOKUP / XLOOKUP JOIN 11

In most companies, the two work as a team: SQL pulls exactly the rows you need from millions and summarises them, and Excel presents the small result as charts and shared files. Excel can even connect straight to a database (Data > Get Data > From Database) and refresh the result with one click.

Other kinds of databases

Relational databases are the most common, but not the only kind:

  • Document databases such as MongoDB store each record as a flexible document, a bit like a form that can have different fields each time.
  • Key-value stores such as Redis are like a giant, very fast dictionary: give it a key, get back a value. They’re often used to make websites faster.
  • Cloud databases are usually the same kinds of databases, run for you by a provider like Microsoft Azure, Amazon or Google, so you don’t manage the server yourself.

As a beginner, start with relational databases and SQL. They’re used almost everywhere, and the ideas carry over to everything else.

Key points

  • A database keeps information correct, shared and fast to find as it grows.
  • Relational databases store data in tables: columns are kinds of information, rows are records.
  • Tables are linked by keys. Orders stores a CustomerID instead of copying the customer’s name and phone.
  • The DBMS (SQL Server, MySQL, PostgreSQL) is the software; the database is your data.
  • You ask a database questions in SQL. You describe the result; the database does the work.
  • Excel is great for small, hands-on work. Shared, growing data and repeatable reports belong in a database.

Practice

Answer these from memory before you look at the answers.

1.1 In ShopDB, what is one row in the Orders table?

1.2 Why does the Orders table store CustomerID instead of the customer’s name and phone?

1.3 Is MySQL a database or a DBMS?

1.4 Name two problems the shop had with its spreadsheet that a database solves.

1.5 Excel, SQL or both? (a) Planning a family holiday budget. (b) A monthly sales report from 2 million orders. (c) A chart of this year’s sales by region for a presentation. (d) An online shop’s website saving every new order.

Answers are in Appendix C of the free PDF.

Enough reading about databases. In the next chapter, you’ll install a free database server and load ShopDB, so you can run every query in this book yourself.

Keep going: Chapters 2 and 3

Chapter 2 gets ShopDB running on your computer, and Chapter 3 starts the real querying. Both are in the free PDF and EPUB.

Questions

Is it really free?

Yes. The preview edition (Chapters 1–3) is free. You only need to enter your email.

MySQL or SQL Server?

Both. Every example shows the MySQL and SQL Server version where they differ, and Chapter 2 helps you choose and install one.

Do I need to know anything before I start?

No. If you can use a spreadsheet, you can follow this book. Chapter 1 starts from zero.

Scroll to Top