SQL Tutorial · Chapter 1 of 32
SQL (Structured Query Language) is the standard language for storing, retrieving and changing data in a relational database. With a handful of English-like keywords such as SELECT, INSERT, UPDATE and DELETE you can ask a database a question and get back exactly the rows you need. This SQL introduction explains what SQL is, how tables are organised and how to run your first query.
What Is a Relational Database?
A relational database stores data in tables. Each table has named columns (fields) and any number of rows (records). Tables are linked through shared key columns: an Orders table stores a CustomerID that points to one row in the Customers table. Popular relational database systems include MySQL, PostgreSQL, SQL Server, Oracle and SQLite, and every one of them understands SQL.
Sample Tables Used in This Course
Every chapter of this course uses the same two small tables, so you can follow along and predict each result yourself before reading it.
| CustomerID | Name | City | Country |
|---|---|---|---|
| 1 | Anita Sharma | Mumbai | India |
| 2 | John Smith | London | UK |
| 3 | Maria Garcia | Madrid | Spain |
| 4 | Wei Chen | Singapore | Singapore |
| 5 | Emma Brown | Sydney | Australia |
| OrderID | CustomerID | Product | Amount | OrderDate |
|---|---|---|---|---|
| 101 | 1 | Laptop | 1200 | 2026-01-05 |
| 102 | 2 | Mouse | 25 | 2026-01-07 |
| 103 | 1 | Monitor | 300 | 2026-01-12 |
| 104 | 3 | Keyboard | 45 | 2026-02-02 |
| 105 | 6 | Headset | 80 | 2026-02-15 |
| 106 | 4 | Laptop | 1150 | 2026-03-01 |
Basic SQL Syntax
SELECT column1, column2
FROM table_name
WHERE condition;
A statement is built from keywords (SELECT, FROM, WHERE), identifiers (table and column names) and values (text in single quotes, numbers without quotes). Statements end with a semicolon. Keywords are not case sensitive, but writing them in capitals makes queries easier to read.
Example 1: Your First Query
SELECT * returns every column of every row in a table.
SELECT * FROM Customers;
| CustomerID | Name | City | Country |
|---|---|---|---|
| 1 | Anita Sharma | Mumbai | India |
| 2 | John Smith | London | UK |
| 3 | Maria Garcia | Madrid | Spain |
| 4 | Wei Chen | Singapore | Singapore |
| 5 | Emma Brown | Sydney | Australia |
Example 2: Choose Specific Columns
SELECT Name, City FROM Customers;
| Name | City |
|---|---|
| Anita Sharma | Mumbai |
| John Smith | London |
| Maria Garcia | Madrid |
| Wei Chen | Singapore |
| Emma Brown | Sydney |
Example 3: Filter Rows
SELECT Name, Country FROM Customers
WHERE Country = 'India';
| Name | Country |
|---|---|
| Anita Sharma | India |
Example 4: Count Rows
SELECT COUNT(*) AS TotalOrders FROM Orders;
| TotalOrders |
|---|
| 6 |
The Main Categories of SQL Commands
| Category | Commands | Purpose |
|---|---|---|
| Query (DQL) | SELECT | Read data |
| Manipulation (DML) | INSERT, UPDATE, DELETE | Add, change or remove rows |
| Definition (DDL) | CREATE, ALTER, DROP | Create or change tables |
| Control (DCL) | GRANT, REVOKE | Manage permissions |
| Transactions (TCL) | COMMIT, ROLLBACK | Save or undo a batch of changes |
Most day-to-day work, and most of this course, is SELECT.
Works in MySQL, SQL Server, PostgreSQL, SQLite
Core SQL is standardised (ANSI SQL), so SELECT, WHERE, JOIN and GROUP BY behave the same in all four systems. Differences appear at the edges: limiting rows (LIMIT vs TOP), string and date functions, and data type names. Each chapter of this course points out those differences where they matter.
Why Learn SQL?
- It is the most requested skill in data analyst, BI and reporting job listings.
- Excel, Power BI, Google Sheets and Python can all pull data straight from SQL queries.
- A basic query takes minutes to learn, yet the same language scales to billions of rows.
How to Follow This Course
Each chapter shows the query and the exact result it produces on the sample tables above, so you can read straight through or type every example into a free online SQLite editor. The chapters build on each other: filtering comes before aggregation, aggregation before joins. Finish with the reference and the 75-question quiz to check what you have learned.
Common Mistakes
- Forgetting single quotes around text values:
WHERE Country = Indiafails,WHERE Country = 'India'works. - Misspelling a table or column name; the database cannot guess what you meant.
- Assuming keywords are case sensitive;
selectandSELECTare identical.
Practice Exercise
- Write a query that returns the Product and Amount of every order.
- Write a query that counts how many customers are in the Customers table.
Show answers
-- 1
SELECT Product, Amount FROM Orders;
-- 2
SELECT COUNT(*) AS TotalCustomers FROM Customers;
-- TotalCustomers = 5
Related Chapters
- SQL Syntax – the rules for writing statements
- SQL SELECT – retrieving data in depth
- SQL WHERE – filtering rows
- SQL from Scratch: full course overview
FAQ
Is SQL a programming language?
SQL is a declarative query language: you describe the result you want and the database works out how to produce it. It is not a general-purpose programming language, but it is often used alongside Python, Java or VBA.
Which database should a beginner install?
SQLite needs no installation and runs in free tools such as DB Browser for SQLite or online editors. MySQL and PostgreSQL are free too and are the most common choices for web applications.
How long does it take to learn SQL?
Most learners can write useful SELECT queries with filters and joins after a few hours of practice. This course covers the full beginner-to-intermediate path in about four hours of reading.
Chapter 1 of 32 · SQL from Scratch: all 32 chapters



