Skip to main content
Module 1 · Lesson 1 of 41/57 in the course~10 min
Module lessons (1/4)

Introduction to SQL

SQL (Structured Query Language) is the standard language with which you query, filter, and update relational databases such as PostgreSQL, MySQL, and SQLite. Its strength is the declarative approach: you describe the result you need and let the database engine choose the fastest reading plan.

Warm-Up Stage

Warm-Up: Your first department query

Read the complete list of company departments with identifier, name and city.

Exercise#sql.m1.l1.e1
Attempts: 0Loading…

Select the id, name, and city columns from the departments table.

Loading editor…
Show hint

Separate the names of the three columns with a comma: SELECT id, name, city.

Solution available after 3 attempts

1. Mental Model: Tables, Keys and Logical Order

Imagine each table as a strict spreadsheet where each column has a unique name and a data type declared (INTEGER, TEXT, NUMERIC, DATE, BOOLEAN):

ElementRole in the databaseExample in employees
TableContainer of entities of the same typeemployees, departments, projects
Row (tuple)A single concrete recordA hired person (Anna Bianchi)
Column (attribute)A homogeneous property for each rowsalary (NUMERIC(10, 2)), hired_on (DATE)
Primary Key (id)Unique identifier of the row in the tableemployees.id = 1
Foreign Key (*_id)A reference to the primary key of another tableemployees.department_id → departments.id
NULLNo known value (not 0, not "")Andrea Costa has department_id = NULL

2. Progressive & Annotated Examples

SQL
-- Esempio 1: leggere tutte le colonne e righe di una piccola tabella anagrafica
SELECT id, name, city
FROM departments;
SQL
-- Esempio 2: proiettare solo le colonne utili di employees evitando SELECT *
SELECT first_name, last_name, salary
FROM employees;
SQL
-- Esempio 3: esplorare i progetti aziendali con budget numerico esatto
SELECT name, budget
FROM projects;
SQL
-- Esempio 4: combinare filtro e proiezione logica (il motore valuta FROM, poi WHERE, poi SELECT)
SELECT title, year, genre
FROM books
WHERE available = TRUE;

3. Interactive Laboratory: How the SQL Engine Thinks

Even if you write SELECT at the beginning of the query, the PostgreSQL engine first reads the source (FROM), then filters (WHERE), then selects the columns (SELECT) and only at the end sorts or cuts (ORDER BY, LIMIT). Explore the sequence step by step:

4. Diagnostic Verification (Quiz)

SQL Quiz#sql.m1.l1.e4
Ready

What is the main difference between a relational table and an in-memory array?

Answer options
SQL Quiz#sql.m1.l1.e5
Ready

In the query SELECT name, city FROM departments;, what does SELECT mean?

Answer options

5. Progressive Practical Laboratory

Explore Stage

Explore: Switch datasets to the Library

Query the authors table of the library catalog to extract name and country of origin.

Exercise#sql.m1.l1.e2
Attempts: 0Loading…

Extract name and country from the authors table of the dataset library.

Loading editor…
Show hint

Add country column next to name in the SELECT clause.

Solution available after 3 attempts

Practice Stage

Practice: Corporate projects and budgets

Query the projects table to read the project name and allocated budget.

Exercise#sql.m1.l1.e3
Attempts: 0Loading…

Show name and budget of all projects from the projects table.

Loading editor…
Show hint

Replace? with name, budget.

Solution available after 3 attempts