What SQL is, and your first query
A database is an organised store of information. A shop's database remembers its customers, its products and every order. A school's remembers students, classes and marks. SQL is the language you use to ask a database questions and to change what it holds. The letters stand for Structured Query Language. Some people say the letters one by one and others say "sequel". Both are fine.
SQL is worth learning because it is everywhere. Banks, hospitals, websites, apps and accounting software keep their data in databases that speak it. The language has changed little in decades, so what you learn here stays useful.
Tables, rows and columns
A database keeps its data in tables. A table looks like a sheet in a spreadsheet.
- Each row is one thing: one customer, one product, one order.
- Each column is one fact about that thing: a name, a city, a price.
- Every table has a name, and so does every column.
Our practice database belongs to a small made-up shop. It has five tables: customers, products, orders, order_items and employees. You can see all of them on the practice database page.
Your first query
A request to the database is called a query. This one asks for everything in the customers table.
SELECT * FROM customers;Result
| id | name | city | state | joined | |
|---|---|---|---|---|---|
| 1 | Asha Verma | Ludhiana | Punjab | 2025-01-15 | asha@example.com |
| 2 | Ravi Kumar | Delhi | Delhi | 2025-02-03 | ravi@example.com |
| 3 | Meena Gill | Amritsar | Punjab | 2025-03-21 | NULL |
| 4 | Kabir Khan | Mumbai | Maharashtra | 2025-04-10 | kabir@example.com |
| 5 | Sunita Rao | Chennai | Tamil Nadu | 2025-05-05 | sunita@example.com |
| 6 | Arjun Mehta | Pune | Maharashtra | 2025-06-18 | NULL |
| 7 | Priya Nair | Kochi | Kerala | 2025-07-02 | priya@example.com |
| 8 | Imran Ali | Delhi | Delhi | 2025-08-14 | imran@example.com |
| 9 | Neha Joshi | Jaipur | Rajasthan | 2025-09-09 | neha@example.com |
| 10 | Tara Singh | Ludhiana | Punjab | 2025-10-27 | NULL |
| 11 | Vikram Das | Kolkata | West Bengal | 2025-11-30 | vikram@example.com |
| 12 | Joy Thomas | Mumbai | Maharashtra | 2026-01-08 | joy@example.com |
12 rows
Read it as a sentence: "select everything from customers".
SELECTsays you want to read data.- The star
*means "all the columns". FROM customersnames the table.- The semicolon
;ends the statement.
The database answers with a table of its own, called the result. Press Try it under any example to open it in the practice box, where you can change it and run it yourself. Nothing you do there can break anything. One button puts the database back as new.
Looking at another table
Change the table name and you get a different table.
SELECT * FROM products;Result
| id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Basmati Rice 5 kg | Grocery | 650 | 40 |
| 2 | Toor Dal 1 kg | Grocery | 160 | 75 |
| 3 | Sunflower Oil 1 L | Grocery | 145 | 60 |
| 4 | Tea 500 g | Grocery | 280 | 0 |
| 5 | Notebook 200 pages | Stationery | 60 | 300 |
| 6 | Ball Pen pack of 10 | Stationery | 90 | 150 |
| 7 | Geometry Box | Stationery | 120 | 45 |
| 8 | School Bag | Stationery | 750 | 20 |
| 9 | LED Bulb 9 W | Electronics | 110 | 200 |
| 10 | Extension Board | Electronics | 399 | 35 |
| 11 | Earphones | Electronics | 499 | 0 |
| 12 | Power Bank | Electronics | 1299 | 18 |
16 rows
Showing the first 12 of 16 rows.
Each product has an id, a name, a category, a price in rupees and the number in stock. The id column is worth noticing. It gives every row a number of its own, so that two products with the same name could still be told apart. Nearly every table has such a column. It is called the primary key.
Does the case of the letters matter?
SQL keywords are not case sensitive. SELECT, select and Select all work. By habit, most people write the keywords in capitals and the table and column names in small letters, because it makes a query easier to read. These lessons follow that habit.
select * from employees;Result
| id | name | department | salary | manager_id | hired |
|---|---|---|---|---|---|
| 1 | Anita Kapoor | Management | 95000 | NULL | 2019-04-01 |
| 2 | Rohit Bansal | Sales | 60000 | 1 | 2020-06-15 |
| 3 | Deepa Iyer | Sales | 48000 | 2 | 2021-09-01 |
| 4 | Manoj Yadav | Sales | 48000 | 2 | 2022-01-10 |
| 5 | Farah Sheikh | Warehouse | 42000 | 1 | 2020-11-20 |
| 6 | Gopal Reddy | Warehouse | 30000 | 5 | 2023-03-05 |
| 7 | Harpreet Kaur | Support | 36000 | 1 | 2021-02-14 |
| 8 | Nikhil Jain | Support | 33000 | 7 | 2024-07-22 |
8 rows
Spaces and line breaks do not matter either. A long query is usually spread over several lines, one part per line.
SELECT *
FROM orders;Result
| id | customer_id | order_date | status |
|---|---|---|---|
| 1 | 1 | 2026-01-05 | delivered |
| 2 | 2 | 2026-01-12 | delivered |
| 3 | 4 | 2026-01-20 | cancelled |
| 4 | 1 | 2026-02-02 | delivered |
| 5 | 5 | 2026-02-14 | delivered |
| 6 | 7 | 2026-02-28 | delivered |
| 7 | 2 | 2026-03-03 | delivered |
| 8 | 8 | 2026-03-15 | delivered |
| 9 | 9 | 2026-03-22 | cancelled |
| 10 | 4 | 2026-04-01 | delivered |
| 11 | 11 | 2026-04-18 | delivered |
| 12 | 1 | 2026-05-06 | delivered |
20 rows
Showing the first 12 of 20 rows.
When you make a mistake
If you misspell a table name, the database cannot find it and says so.
SELECT * FROM customer;What the database says
Error: no such table: customerThe table is called customers, with an s. Error messages in SQL are short and usually name the word that caused the trouble. Read them. They save time.
What kind of SQL is this?
There are several database products: MySQL, PostgreSQL, SQL Server, Oracle, SQLite and others. All of them understand SQL, and the core of the language is the same in each. They differ in small ways, a little like the English of India, Britain and America. The practice box on this site runs SQLite. Wherever another product does something differently, the lesson tells you. There is a summary on the page about SQL in different databases.
What comes next
The next eight lessons are all about reading data: choosing columns, filtering rows, sorting and limiting. Reading is the largest part of SQL and the safest to practise, because a SELECT never changes anything.
Try it yourself
Exercise 1. Show everything in the orders table.
Show one answer
SELECT * FROM orders;| id | customer_id | order_date | status |
|---|---|---|---|
| 1 | 1 | 2026-01-05 | delivered |
| 2 | 2 | 2026-01-12 | delivered |
| 3 | 4 | 2026-01-20 | cancelled |
| 4 | 1 | 2026-02-02 | delivered |
| 5 | 5 | 2026-02-14 | delivered |
| 6 | 7 | 2026-02-28 | delivered |
| 7 | 2 | 2026-03-03 | delivered |
| 8 | 8 | 2026-03-15 | delivered |
| 9 | 9 | 2026-03-22 | cancelled |
| 10 | 4 | 2026-04-01 | delivered |
| 11 | 11 | 2026-04-18 | delivered |
| 12 | 1 | 2026-05-06 | delivered |
20 rows
Showing the first 12 of 20 rows.
Exercise 2. Show everything in the employees table.
Show one answer
SELECT * FROM employees;| id | name | department | salary | manager_id | hired |
|---|---|---|---|---|---|
| 1 | Anita Kapoor | Management | 95000 | NULL | 2019-04-01 |
| 2 | Rohit Bansal | Sales | 60000 | 1 | 2020-06-15 |
| 3 | Deepa Iyer | Sales | 48000 | 2 | 2021-09-01 |
| 4 | Manoj Yadav | Sales | 48000 | 2 | 2022-01-10 |
| 5 | Farah Sheikh | Warehouse | 42000 | 1 | 2020-11-20 |
| 6 | Gopal Reddy | Warehouse | 30000 | 5 | 2023-03-05 |
| 7 | Harpreet Kaur | Support | 36000 | 1 | 2021-02-14 |
| 8 | Nikhil Jain | Support | 33000 | 7 | 2024-07-22 |
8 rows
Exercise 3. Show everything in the order_items table. How many columns does it have?
Show one answer
SELECT * FROM order_items;| order_id | product_id | quantity |
|---|---|---|
| 1 | 1 | 2 |
| 1 | 2 | 1 |
| 1 | 5 | 4 |
| 2 | 9 | 4 |
| 2 | 10 | 1 |
| 3 | 12 | 1 |
| 4 | 3 | 2 |
| 4 | 4 | 1 |
| 5 | 13 | 2 |
| 5 | 6 | 1 |
| 6 | 14 | 1 |
| 7 | 5 | 10 |
39 rows
Showing the first 12 of 39 rows.
Examples on this page were run with SQLite 3.50.4 on 12 November 2026. The results shown are the real results.
This is an independent learning site. It is not connected with the makers of any database product. MySQL, PostgreSQL, SQL Server, Oracle and SQLite are named only so that you know where a piece of SQL works. The shop, its customers and its staff in the practice database are made up.