Nishaglobal Education logo

Databases, tables and your first SQL query

Learn what a database, a table and SQL are, set up the free DB Browser for SQLite with the course's sample shop database, and run your first SELECT query.

Lesson 1 of 1230 minQuiz: 4 questions

🎯 By the end of this lesson you will be able to:

  • Explain what a database, table, row and column are
  • Install DB Browser for SQLite and load the sample shop database
  • Run a query and read the result
Outline
  1. What you'll learn and why it matters
  2. Tables, rows and columns
  3. Set up DB Browser for SQLite
  4. Your first query
  5. Practice
  6. Common mistakes
  7. Recap
  8. Quiz
  9. Mark lesson complete

What you'll learn and why it matters

Almost every app you use, from online shops to banking apps to your college's results portal, keeps its information in a database: an organised store of data that a computer can search quickly. SQL (Structured Query Language, often said β€œsequel” or β€œS-Q-L”) is the language used to ask databases questions, such as β€œwhich customers in India ordered this month?”. Analysts, developers, testers and product managers use it every day, and it is one of the most requested skills in job adverts.

In this lesson you set up a free database tool, load a small online shop's data, and ask it your first question.

Tables, rows and columns

Most databases store data in tables, which look a lot like a spreadsheet. Each table holds one kind of thing: customers, products or orders.

customerscustomer_idnamecity1Asha PatelMumbai2Ravi KumarBengaluru3Meera NairKochicolumn: cityone kind of informationprimary keyunique for every rowShaded row: one record (Ravi Kumar)
A table has named columns (the kinds of information) and rows (one record each). The primary key column gives every row a unique id.
WordMeaningIn the customers table
TableA collection of records of one kindcustomers
ColumnOne kind of information, with a namename, city, country
RowOne record: one customerAsha Patel from Mumbai
Primary keyA column whose value is unique for every rowcustomer_id

A database usually holds several related tables. Our sample shop has three: customers, products and orders. A program that manages databases is called a database management system. We use SQLite, which is free, needs no server, and stores a whole database in one file. The SQL you learn works almost the same in MySQL, PostgreSQL, SQL Server and Oracle.

Set up DB Browser for SQLite

DB Browser for SQLite is a free, open-source program for creating and querying SQLite databases. It works on Windows, macOS and Linux. This course was checked against version 3.13.1, the latest release when it was reviewed.

  1. Go to sqlitebrowser.org/dl and download the version for your computer. On Windows choose the standard installer (or the .zip (no installer) version if you cannot install programs on your computer). On macOS choose the Universal .dmg.
  2. Install it and open DB Browser for SQLite.
  3. Download the sample database script below and save it somewhere easy to find, such as a folder called sql-course.

⬇ Download shop.sqlCreates the customers, products and orders tables for a small made-up online shop. All names and emails are fictional.

Now load the sample data:

  1. In DB Browser, click New Database (or press Ctrl + N). Save it as shop.db in your sql-course folder.
  2. A window may open asking you to define a table. Click Cancel; the script will create the tables for you.
  3. Open shop.sql in a text editor (such as Notepad or TextEdit), select everything (Ctrl + A, or Cmd + A on a Mac) and copy it.
  4. In DB Browser, click the Execute SQL tab, paste the script into the editor, and press F5 (or Ctrl + Return) to run it.
  5. Click Write Changes to save the data to shop.db.
  6. Click the Browse Data tab and choose the customers table. You should see 10 customers.

Prefer the command line? SQLite also has a command-line program called sqlite3 (included on macOS and most Linux systems; for Windows it is available from sqlite.org). From your sql-course folder:

In a terminal, inside your sql-course folder
sqlite3 shop.db < shop.sql
sqlite3 shop.db

Then type queries at the sqlite> prompt, and .quit to leave.

Your first query

A request for data is called a query. In the Execute SQL tab, delete what is there, type this and press F5:

SQL
SELECT * FROM customers;

Result: 10 rows

Query result
customer_idnamecitycountryemailjoined_on
1Asha PatelMumbaiIndiaasha@example.com2025-01-15
2Ravi KumarBengaluruIndiaravi@example.com2025-02-03
3Meera NairKochiIndiaNULL2025-03-21
4John SmithLondonUKjohn@example.com2025-03-30
5Fatima KhanDubaiUAEfatima@example.com2025-04-12
6Li WeiSingaporeSingaporeliwei@example.com2025-05-08
7Sara LopezTorontoCanadaNULL2025-06-19
8Arjun SinghDelhiIndiaarjun@example.com2025-07-02
9Emma BrownSydneyAustraliaemma@example.com2025-08-25
10Kofi MensahNULLGhanakofi@example.com2025-09-14
PartMeaning
SELECTβ€œGive me...”. Every query that reads data starts with SELECT.
*β€œ...every column...”
FROM customersβ€œ...from the customers table.”
;Marks the end of the statement. It is needed when you run several statements together, so always add it.

The result appears in the grid under the editor. Some cells show NULL. That means β€œno value”: Meera and Sara did not give an email address, and Kofi's city is unknown. You will learn to work with NULL in lesson 5.

Practice

Guided exercise

Look at the products

Show every column of every row in the products table. How many products does the shop sell, and which is the most expensive?

  1. In the Execute SQL tab, type SELECT * FROM followed by the table name.
  2. End with a semicolon and press F5.
  3. Count the rows and read the price column.
Show the solution
Solution
SELECT * FROM products;

Result: 8 rows

Query result
product_idnamecategoryprice
1Notebook A5Stationery120
2Gel Pens (pack of 5)Stationery90
3Python Basics BookBooks450
4SQL Pocket GuideBooks350
5Desk LampElectronics1200
6USB-C CableElectronics299
7Water BottleHome399
8Coffee MugHome249

How to get there: There are 8 products. The Desk Lamp, at 1200 (prices are in Indian rupees), is the most expensive. In lesson 4 you will make SQL find that for you instead of reading the whole table.

Your turn

Look at the orders

Show every row of the orders table. Which column tells you who placed each order?

Show the solution
Solution
SELECT * FROM orders;

How to get there: There are 15 orders. customer_id holds the id of the customer who placed the order, and product_id the product they bought. Numbers instead of names may look odd; lesson 8 explains why databases do this, and lesson 9 shows how to bring the names back.

Common mistakes

Misspelling the table name

You see: no such table: customer

Fix: Check the exact name in the Database Structure tab. Our table is customers, plural.

Forgetting to click Write Changes after loading the data

You see: Next time you open shop.db, the tables are missing

Fix: Load shop.sql again and click Write Changes (DB Browser keeps changes pending until you do).

Running the query in the wrong place

You see: Nothing happens when you type in Browse Data

Fix: Queries go in the Execute SQL tab; press F5 to run them.

Typing smart quotes copied from a document

You see: unrecognized token: "β€˜"

Fix: Type quotes yourself in the editor; SQL needs plain straight quotes.

Recap

  • A database stores data in tables made of columns (kinds of information) and rows (records).
  • A primary key column, such as customer_id, gives every row a unique id.
  • SQL is the language for asking databases questions. SELECT * FROM table; shows every column and row.
  • NULL means no value. SELECT only reads data, so it is always safe to run.

Key terms

Database
An organised store of data that a computer can search and update quickly.
Table
A set of rows of one kind of thing, with named columns.
Query
A request for data, written in SQL.
NULL
A marker meaning a value is missing or unknown.

Check your understanding

Answer all 4 questions, then check your answers to see an explanation for each one.

  1. 1. In a table of customers, what is one row?

  2. 2. What does `SELECT * FROM products;` do?

  3. 3. What is special about a primary key column?

  4. 4. A cell shows NULL. What does that mean?

Answer all 4 questions to check.

Read more

Mark this lesson complete

Finished this lesson?

When you have worked through the examples and exercises, mark it complete to save your progress.