← All lessons
SQL from zero · Lesson 1 of 10

Tables, rows and columns

A database is where a program keeps its data so it can find it again: a shop's products, its customers, every order anyone has placed. Most databases keep their data in tables. A table looks a lot like a spreadsheet. Each row is one thing, like one product, and each column is one fact about it, like its name or its price.

Unlike a spreadsheet, a table is strict. Every row has exactly the same columns, and each column holds one kind of value: whole numbers, decimal numbers, text or dates. That strictness is what lets a database answer questions about millions of rows quickly and correctly.

SQL is the language for asking a database those questions. (Say it "S-Q-L" or "sequel"; both are common.) You write a short request called a query, and the database answers with a table of results. SQL is about fifty years old and nearly every database speaks it, from the one inside your phone to the huge ones banks and websites run. It reads almost like English, and you don't need to know any other programming to use it.

This course uses the database of a small made-up shop that sells garden and outdoor things. Here is your first query. It shows the whole products table:

SELECT * FROM products;
Returns
id | name        | category | price
---+-------------+----------+------
1  | Duck feeder | Garden   | 24
2  | Bird bath   | Garden   | 45.5
3  | Rain boots  | Clothing | 40
4  | Raincoat    | Clothing | 59
5  | Pond net    | Garden   | 12.5
6  | Field guide | Books    | 18
7  | Sketchbook  | Books    | 9.75
8  | Binoculars  | Outdoors | 120
(8 rows)

Read it as a sentence: select everything from the products table. SELECT and FROM are SQL's own words, called keywords. * (a star) means every column, and products is the name of the table. The semicolon ; marks the end of the query, like a full stop at the end of a sentence.

The result is a table too: 8 rows, one per product, and 4 columns. id is a number that gives each row its own label, so the database can always tell two rows apart, even if two products had the same name. name and category are text, and price is a number.

Every example in these lessons really runs, in your browser, on a small database engine called SQLite. Returns under an example shows exactly what came back, with the number of rows at the end. In the practice below each lesson, you write your own queries: type one in and its result appears as you type.

SQL doesn't mind capital letters in its keywords: select * from products; works just the same. People usually write keywords in capitals so they stand out from the names of tables and columns, and this course does too.

Practice

In the products table, what is one row?

More info

Quick reference

databaseWhere a program keeps its data, usually as tables.
table, row, columnA table of rows (one thing each) and columns (one fact each).
SQLThe language for asking a database questions.
queryOne request to the database. The answer is a table.
SELECT * FROM t;Every column and every row of table t.
;Ends a query.

The other AI and data engineering courses