appDBMSdisk1SELECT name2FROM books3WHERE year > 2000desknameCoralineThe RoadWonderid name year1 Dune 19652 Coraline 20023 Holes 19984 The Road 20065 Wonder 20126 Piranesi 2020'soon'log
Back row: the programs that use the data, the DBMS and its diskFront: the SQL query, the result, and the books table (rows and columns)Envelopes: the query, the answer, a new row and the 'saved' replyAt the back: two programs that use the data (the library app and the front desk), the DBMS and its disk. In front: the app's SQL query, the result it gets back, and the books table. The query is answered in the order FROM, WHERE, SELECT: take the books table, keep the rows with a year after 2000, then keep only the name column. The DBMS refuses a year that is not a whole number, lets two users work at once, and logs every change on disk before it calls it saved. Without ORDER BY, SQL does not promise any order for the rows of an answer. The figure shows them in id order; add ORDER BY id to ask for that.

What a database is

  1. A database is an organised store of data. It keeps the data so that many programs and people can find it, change it and trust it. Here, one database holds a small library’s books.

Your first query

Many users, one truth

What happens

;; step 1/11 · database
database   an organised store of data
it lets many programs and people
  find it      (ask questions)
  change it    (add, edit, delete)
  trust it     (rules, no half changes, no lost changes)
this one: the books of a small library

Without ORDER BY, SQL does not promise any order for the rows of an answer. The figure shows them in id order; add ORDER BY id to ask for that. Real databases rarely test every row one by one: an index can find the matching rows directly, as a later lesson shows. The answer is the same.