
📎 This article includes 5 downloadable practice files ↓
In this article
An Excel sheet holds one table. A database holds many related tables, and SQL (Structured Query Language, said “sequel” or “S-Q-L”) is how you ask them questions. The good news: the basic sentence is short and reads almost like English.
Tables, rows, columns
The practice database shop.db has three tables:
| Table | Columns | Rows |
|---|---|---|
| customers | customer_id, name, city, region, gstin, joined | 12 |
| products | product_id, name, category, price, gst_rate | 10 |
| orders | order_id, order_date, customer_id, product_id, qty, status | 300 |
Like an Excel table: each row is one record, each column one field. The _id columns link tables together (Lesson 6).
Set up in two minutes
- Install DB Browser for SQLite (free, sqlitebrowser.org) on Windows or Mac.
- Open Database › choose shop.db.
- Browse Data shows a table; Execute SQL is where you type queries. Press Ctrl+Enter (or F5) to run.
SELECT and FROM
SELECT name, price FROM products;
“Show the name and price columns from the products table.” The semicolon ends the statement. SQL keywords aren’t case-sensitive; writing them in capitals just makes queries easier to read.
SELECT * FROM products; -- * means every column
Calculated columns and AS
SELECT name, price, price * (1 + gst_rate) AS price_with_gst
FROM products;
AS gives the calculated column a name (an alias). Use + – * / and brackets as in Excel.
DISTINCT: no repeats
SELECT DISTINCT region FROM customers; -- North, South, East, West once each
LIMIT: just a few rows
SELECT * FROM orders LIMIT 5;
Always add LIMIT when exploring a large table. (SQL Server uses SELECT TOP 5 … instead; Oracle uses FETCH FIRST 5 ROWS ONLY.)
Comments
-- like this for one line, /* like this */ for several. Use them to explain why a query exists.
Where beginners go wrong
| Mistake | Error |
|---|---|
Comma after the last column: SELECT name, price, FROM |
Syntax error near FROM |
| Misspelt column | no such column |
| Text in double quotes | Use single quotes for text: ‘South’ |
| Forgetting FROM | Error, or a single calculated row |
Practice
Download shop.db and this lesson’s exercise file below. Open the database in the free DB Browser for SQLite (or sqlite3 shop.db), paste the exercises into the Execute SQL tab and write a query for each task. The expected result is printed under every task; answers are at the bottom of the file.
📎 Practice files for this article
- 📄Practice database (SQLite)shop.db: 12 customers, 10 products and 300 orders (April-September 2026).⬇ DB · 28 KB
- 🗃️Lesson 1 exercisesTasks with the expected result under each, and answers at the bottom.⬇ SQL · 2 KB
- 🧾customers.csvThe customers table as CSV (for other databases or Excel).⬇ CSV · 709 B
- 🧾products.csvThe products table as CSV.⬇ CSV · 386 B
- 🧾orders.csvThe orders table as CSV.⬇ CSV · 9 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.