SQL (Structured Query Language) is how you talk to a relational database — asking it to store, retrieve, and organise data stored in tables. This page gets you from zero to running your first query.
What Is SQL?
SQL is a language for working with data stored in tables inside a relational database (MySQL, PostgreSQL, SQLite, SQL Server, and others all use SQL with minor dialect differences). Unlike R or Python, SQL is declarative - you describe WHAT data you want, and the database figures out HOW to get it.
You do not need to install anything heavy to practice: SQLite is a free, file-based database built into Python, and free browser tools like DB Fiddle or SQLite Online let you run queries instantly.
Tables, Rows, and Columns
A database is a collection of tables. Each table is a grid: columns define the type of information (name, age, score), and rows are individual records. This guide uses a simple students table throughout its examples.
-- the students table used throughout this guide -- id | name | age | score | class -- 1 | Rafi | 23 | 88 | A -- 2 | Meera | 25 | 92 | A -- 3 | Zayn | 21 | 76 | B -- 4 | Nadia | 22 | 65 | B
Your First Query
SELECT * FROM students;
id | name | age | score | class 1 | Rafi | 23 | 88 | A 2 | Meera | 25 | 92 | A 3 | Zayn | 21 | 76 | B 4 | Nadia | 22 | 65 | B
SELECT * means "give me every column"; FROM students tells the database which table to read from. The semicolon marks the end of the statement.
SQL Keywords Are Not Case-Sensitive (But Style Matters)
-- these two queries do exactly the same thing select * from students; SELECT * FROM students;
Comments
-- a single-line comment starts with two dashes SELECT name FROM students; -- inline comments work too /* a multi-line comment spans several lines like this */
Key Points
- SQL is a declarative language for querying relational (table-based) databases.
- A table is organised into columns (fields) and rows (records).
- SQL keywords are case-insensitive, but UPPERCASE keywords with lowercase table/column names is the standard style.
- -- starts a single-line comment; /* ... */ wraps a multi-line comment.