Pull rows out, then filter them

INPUT · Slides

A look inside a database

01 / 05

Where does the data live?

The books in a library, the record of a club, the stock in a shop. Everything an app needs to remember is kept together in a store called a database.

SQL is the language you use to ask that database to show you something, or to add something to it. Let us start learning how to talk to it.

02 / 05

A database is a pile of tables

What is inside a database is shaped like a table. One database holds any number of them.

A library database might hold these three.

  • books … the books
  • members … the people who join
  • loans … who borrowed what

03 / 05

Down the columns, across the rows

A table is shaped like squared paper.

  • Column … an item like id, title or author. It runs down
  • Record (row) … one book. It runs across

The good thing about a table is that every row has the same columns.

04 / 05

Seeing a whole table

Write SELECT * FROM table; and the whole contents of that table come back.

* (an asterisk) means "every column". The ; (semicolon) at the end says "that is the end of the instruction".

SELECT * FROM books;

Result

1 | The Star Map | Minato Asahi | A | 210
2 | The Lost Kitten | Yui Kusunoki | B | 96
3 | Wonders of Science | Ren Todo | C | 320
4 | The Town Under the Sea | Minato Asahi | A | 180
5 | Morning at the Bakery | Yui Kusunoki | B | 128

05 / 05

Same writing for any table

Swap the name of the table and you can look inside any of them. When you meet a database you do not know, pouring everything out and having a look is the first step.

Let us write some.

SELECT * FROM members;

Result

1 | Minami | 1
2 | Sota | 2
3 | Himari | 3