Lesson 1 of 10 · 12 min · 1 hands-on step

Tables & SELECT Queries

Read data with SELECT, filter it with WHERE and sort it with ORDER BY.

What is a database?

A relational database stores data in tables, like spreadsheets with strict rules. Each row is a record (one employee), and each column is a field (name, salary). Most web apps you'll work on use one: PostgreSQL, MySQL or SQLite.

Reading data

SQL · try it
SELECT name, salary FROM employees;
SELECT * FROM employees;           -- every column (fine for exploring)

Filtering

SQL · try it
SELECT name FROM employees WHERE salary >= 100000;
SELECT name FROM employees WHERE department_id = 1 AND hired > '2022-01-01';
SELECT name FROM employees WHERE name LIKE 'A%';  -- starts with A

Sorting and limiting

SQL · try it
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 3;

SQL keywords aren't case sensitive, but writing them in UPPERCASE is the convention and makes queries easier to scan.

The exercise runs a real SQLite database in your browser, and the test compares your result with the expected rows.

🧪 Practice

The employees table has columns id, name, department_id, salary, hired.

Return the name and salary of every employee earning more than 90000, highest salary first.

SQL
-- Explore first:
SELECT * FROM employees;

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. Which clause filters rows?

  2. What is a primary key?

Create a free account to track your progress.