AI Hints
Homeโ€บSQL Tutorialโ€บWelcome to SQL
SQL ยท Lesson 3 of 126

Getting Set Up

SQLite in two minutes.

โฑ 2 min readโ–ถ Video at 2:59๐ŸŽ“ Free
Watch this lesson in the SQL courseWatch on YouTube โ†—Full SQL course

There are many database programs, like MySQL, Postgres, and SQL Server. In this course we'll use SQLite. It's free, it's tiny, and the whole database lives in a single file. And the good news is that everything you learn works almost the same in the others.

Getting Set Up
From the video: Getting Set Up
  • Many database programs
  • We use SQLite: free and tiny
  • Your skills carry over

Get ready in three steps

Getting ready takes three steps. First, install SQLite. On a Mac it's already there, and on Windows or Linux you download it from the SQLite website. Second, download the Riverside Books file, called shop dot DB, from the link in the description. Third, write your question in a text file, and run it.

  1. Install SQLitealready on a Mac
  2. Get shop.dblink in description
  3. Write and runa .sql file
Get ready in three steps
From the video: Get ready in three steps

Your very first run

Let's prove it works. This little file asks for the first five books. Don't worry about the words yet. We'll learn each one in a moment. In the terminal, we give SQLite the database, and feed it our file. Run it. And there's our first answer, as a neat table. You've just run SQL.

first.sqlsql
SELECT *
FROM books
LIMIT 5;
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ book_id โ”‚          title           โ”‚  author   โ”‚   genre    โ”‚ price โ”‚ stock โ”‚ published โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1       โ”‚ The Silent Orchard       โ”‚ Mira Hale โ”‚ Mystery    โ”‚ 14.99 โ”‚ 58    โ”‚ 2016      โ”‚
โ”‚ 2       โ”‚ Code of the River        โ”‚ Tom Avery โ”‚ Thriller   โ”‚ 12.99 โ”‚ 26    โ”‚ 2021      โ”‚
โ”‚ 3       โ”‚ Stars Over Lagos         โ”‚ Ada Obi   โ”‚ Romance    โ”‚ 9.99  โ”‚ 47    โ”‚ 2024      โ”‚
โ”‚ 4       โ”‚ A Short History of Bread โ”‚ Lena Fox  โ”‚ History    โ”‚ 19.99 โ”‚ 53    โ”‚ 2018      โ”‚
โ”‚ 5       โ”‚ Python for Curious Minds โ”‚ Raj Mehta โ”‚ Technology โ”‚ 34.99 โ”‚ 17    โ”‚ 2023      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

How every example works

Every example in this course works the same way. The question goes in a file that ends in dot SQL. Then you run SQLite with the database, and the file. The answer appears in the terminal. Pause the video whenever you like, and type the examples yourself. Typing them is how they stick.

Writea .sql file
Runsqlite3 -box shop.db < file.sql
Readthe table it prints
Practisetype every example

Summary

You're all set up, and you've run your first query. Now let's understand it, word by word, starting with the most important word in SQL.

Key takeaways
  • SQLite: free and simple
  • shop.db holds the data
  • Write a file, run it, read it
Next up: Your First SELECT โ€” get every column