If you’ve never written a line of SQL, this is the right place to start. I’ll show you the five commands I use every day at work, using one small table, with the real result of every query. You don’t need to memorise anything, and you don’t need any experience with programming.
By the end of this guide you’ll have written your first real queries, and you’ll know exactly what to learn next.
Quick answer: what is SQL?
SQL (Structured Query Language) is the language you use to ask a database questions and to change its data. Five commands take a beginner a long way:SELECT reads data, WHERE filters it, ORDER BY sorts it, COUNT counts rows, and GROUP BY summarises them.

Table of Contents
What Is SQL?
SQL is short for Structured Query Language. Some people say each letter, “S-Q-L”, and some say “sequel”. Both are fine, and you’ll hear both at work.
A database keeps its information in tables. SQL is how you talk to it. The nice part is that you don’t tell the database how to find the data step by step. You describe what you want, and the database works out the fastest way to get it.
With SQL you can:
- Read data: “show me all customers from Egypt”
- Add data: “save this new customer”
- Change data: “update Sara’s email address”
- Remove data: “delete orders that were cancelled”
Almost every app you use has a database behind it, and almost every database understands SQL. That’s why it’s such a good skill to learn: the same basics work in SQL Server, MySQL, PostgreSQL, SQLite and many others. If the word “database” itself is still new to you, read What Is a Database? first. It takes five minutes.
The Table We’ll Use
Every example in this guide uses this small customers table:
| id | name | country | |
|---|---|---|---|
| 1 | Sara Ahmed | sara@email.com | Egypt |
| 2 | John Smith | john@email.com | UK |
| 3 | Mei Lin | mei@email.com | China |
| 4 | Carlos Rivera | carlos@email.com | Mexico |
| 5 | Aisha Noor | aisha@email.com | Egypt |
Each row is one customer. Each column is one piece of information about them. If you’ve used Excel, this will feel familiar. The difference is that a database can hold millions of rows and still answer your questions in a moment. (SQL vs Excel explains when a spreadsheet stops being enough.)
Set it up yourself (5 minutes)
You’ll learn much faster if you type the queries yourself instead of only reading them. Run this once to create the same table:
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) NOT NULL,
country VARCHAR(50) NOT NULL
);
INSERT INTO customers (id, name, email, country) VALUES
(1, 'Sara Ahmed', 'sara@email.com', 'Egypt'),
(2, 'John Smith', 'john@email.com', 'UK'),
(3, 'Mei Lin', 'mei@email.com', 'China'),
(4, 'Carlos Rivera', 'carlos@email.com', 'Mexico'),
(5, 'Aisha Noor', 'aisha@email.com', 'Egypt');
Don’t worry about understanding every word yet. CREATE TABLE describes the columns, and INSERT adds the five rows. You’ll learn both properly later.
Where can you run it? Any of these is free:
- PostgreSQL: follow the PostgreSQL tutorial for beginners, which gets you running in about ten minutes.
- SQL Server Developer Edition with SQL Server Management Studio (SSMS), if you’re on Windows or plan to work with Microsoft tools.
- An online SQL playground such as SQLite Online, if you can’t install anything. Nothing to set up, just paste and run.
1. SELECT: Read Data From a Table
SELECT is the command you’ll use more than any other. It reads data from a table. You tell it which columns you want, and which table they come from:
SELECT name, email
FROM customers;
Result:
| name | |
|---|---|
| Sara Ahmed | sara@email.com |
| John Smith | john@email.com |
| Mei Lin | mei@email.com |
| Carlos Rivera | carlos@email.com |
| Aisha Noor | aisha@email.com |
To get every column at once, use *, which means “all columns”:
SELECT *
FROM customers;
SELECT * is handy when you’re exploring a table for the first time. In real projects, list the columns you actually need. It’s faster on big tables, and your query keeps working the same way if someone adds new columns later.
2. WHERE: Keep Only the Rows You Want
WHERE adds a condition. The database checks every row, and only keeps the rows where the condition is true:
SELECT *
FROM customers
WHERE country = 'Egypt';
Result:
| id | name | country | |
|---|---|---|---|
| 1 | Sara Ahmed | sara@email.com | Egypt |
| 5 | Aisha Noor | aisha@email.com | Egypt |
Notice the single quotes around 'Egypt'. Text values always go in single quotes. Numbers don’t need any: WHERE id = 3.
Here are the conditions you’ll use most:
| Operator | Meaning | Example |
|---|---|---|
= | equals | WHERE country = 'Egypt' |
<> or != | not equal | WHERE country <> 'UK' |
> / < | greater / less than | WHERE id > 3 |
>= / <= | greater / less than or equal | WHERE id <= 2 |
LIKE | matches a text pattern | WHERE name LIKE 'S%' |
LIKE deserves a closer look. The % sign means “any characters”, so 'S%' means “starts with S”:
SELECT name
FROM customers
WHERE name LIKE 'S%';
-- Sara Ahmed
There’s much more you can do with filters, like combining conditions with AND and OR. SQL WHERE, ORDER BY and LIMIT and SQL LIKE, IN and BETWEEN cover it step by step.
3. ORDER BY: Sort the Results
ORDER BY sorts your results by a column. ASC means smallest first (A to Z, 1 to 9). DESC means largest first (Z to A, 9 to 1).
SELECT name
FROM customers
ORDER BY name ASC;
-- Aisha Noor, Carlos Rivera, John Smith, Mei Lin, Sara Ahmed
SELECT name
FROM customers
ORDER BY id DESC;
-- Aisha Noor (5), Carlos Rivera (4), Mei Lin (3), John Smith (2), Sara Ahmed (1)
You can filter and sort in the same query. WHERE always comes before ORDER BY:
SELECT name
FROM customers
WHERE country = 'Egypt'
ORDER BY name;
-- Aisha Noor, Sara Ahmed
One thing that surprises many beginners: without ORDER BY, the database returns rows in whatever order is easiest for it, and that order can change. If the order matters to you, always ask for it.
4. COUNT: How Many Rows?
COUNT(*) counts rows. It’s the first step into reports.
SELECT COUNT(*)
FROM customers;
-- 5
Add a WHERE, and it counts only the rows that match:
SELECT COUNT(*)
FROM customers
WHERE country = 'Egypt';
-- 2
5. GROUP BY: Summarise by Group
GROUP BY is where SQL starts to feel powerful. Picture the database sorting the rows into piles, one pile for each country, and then counting each pile:
SELECT country, COUNT(*)
FROM customers
GROUP BY country;
Result (the order of the rows may differ on your screen):
| country | count |
|---|---|
| Egypt | 2 |
| UK | 1 |
| China | 1 |
| Mexico | 1 |
Imagine the same query on a table with 100,000 customers. It’s still one short line, and the answer still comes back in a moment. SQL GROUP BY and Aggregate Functions shows the other summaries you can make, like SUM and AVG.
Putting It All Together
Let’s use everything in one query. Say you run an online shop and want to see which countries most of your customers come from, biggest first:
SELECT country, COUNT(*) AS total_customers
FROM customers
GROUP BY country
ORDER BY total_customers DESC, country;
Result:
| country | total_customers |
|---|---|
| Egypt | 2 |
| China | 1 |
| Mexico | 1 |
| UK | 1 |
Two new things here. AS total_customers gives the count column a readable name. That’s called an alias. And the second sort column, country, breaks the tie between the three countries that each have one customer, so the result is always in the same order.
Try reading the query out loud: “from customers, group by country, count each group, and sort with the biggest first.” Once you can read SQL like a sentence, writing it gets much easier. (More on aliases in SQL DISTINCT and Column Aliases.)
Practice: Five Questions to Try
Use the customers table you created. Write each query yourself first, then compare with the answers below. Getting a different result isn’t a failure. Working out why it’s different is exactly how you learn.
- Show the name and country of every customer.
- Show the customers who are not from Egypt, sorted by name.
- How many customers are from the UK?
- Find the customers whose name contains the letters “ar”.
- Show each country that has more than one customer. (Hint: look up
HAVINGin the mistakes section below.)
Answers
-- 1. All five customers with their country
SELECT name, country
FROM customers;
-- 2. Carlos Rivera, John Smith, Mei Lin
SELECT name, country
FROM customers
WHERE country <> 'Egypt'
ORDER BY name;
-- 3. 1
SELECT COUNT(*)
FROM customers
WHERE country = 'UK';
-- 4. Sara Ahmed, Carlos Rivera
SELECT name
FROM customers
WHERE name LIKE '%ar%';
-- 5. Egypt 2
SELECT country, COUNT(*) AS total_customers
FROM customers
GROUP BY country
HAVING COUNT(*) > 1;
In question 4, the % on both sides means “anything before, anything after”, so it finds “ar” anywhere in the name.
Common Beginner Mistakes
- Double quotes around text. Write
'Egypt', not"Egypt". In SQL Server and PostgreSQL, double quotes mean a column or table name, not a value, so the query fails or does something unexpected. - Writing
= NULL. An empty value isNULL, and you check for it withIS NULL.= NULLnever matches anything. NULL in SQL Explained Simply explains why. - Expecting a fixed order without ORDER BY. No
ORDER BYmeans no promise about the order. - Using SELECT * everywhere. Fine for exploring, but list your columns in anything you keep.
- Mixing up WHERE and HAVING.
WHEREfilters rows before they’re grouped.HAVINGfilters the groups afterGROUP BY, like “countries with more than one customer” in question 5.
Quick Recap
| Command | What it does | Example |
|---|---|---|
SELECT | Reads columns from a table | SELECT name, email FROM customers |
WHERE | Keeps only matching rows | WHERE country = 'Egypt' |
ORDER BY | Sorts the result | ORDER BY name ASC |
COUNT(*) | Counts rows | SELECT COUNT(*) FROM customers |
GROUP BY | Makes one row per group | GROUP BY country |
AS | Gives a column a readable name | COUNT(*) AS total_customers |
HAVING | Filters groups | HAVING COUNT(*) > 1 |
Frequently Asked Questions
Is SQL hard to learn?
The basics aren’t. SQL reads almost like English, and the five commands in this guide already answer a lot of real questions. The harder parts, like joining many tables or making big queries fast, come later, one step at a time.
How long does it take to learn the basics of SQL?
If you practise for about 30 minutes a day, most people are comfortable with SELECT, WHERE, ORDER BY and GROUP BY within two or three weeks. Practice on a table you care about (your expenses, a football league, a list of books) and it goes even faster.
Which database should I start with?
It matters less than you’d think, because the basics are the same everywhere. PostgreSQL and MySQL are free and popular for websites. SQL Server is common in companies, especially with Microsoft tools. Pick one and stick with it while you learn. This cheat sheet shows the small differences when you switch later.
Is SQL a programming language?
Yes, but a special kind. In most programming languages you write the steps to follow. In SQL you describe the result you want, and the database decides the steps. That’s one reason it’s easier to start with than languages like Python or C#.
What to Learn Next
You now know the core of SQL. Here’s a good order for the next steps:
- WHERE, ORDER BY and LIMIT: combine conditions, get the “top 5” and page through results.
- DISTINCT and aliases: remove duplicates and name your columns.
- GROUP BY and aggregate functions: SUM, AVG, MIN and MAX per group.
- SQL JOINs: connect two tables, the most important idea after this one.
- INSERT, UPDATE and DELETE: add and change data safely.
Don’t rush through them. Practise each one on real data until it feels easy. The Learn SQL Roadmap shows the full path from here to a job-ready level.
Related articles
- What Is a Database? Explained Simply: the foundation behind everything in this guide.
- NULL in SQL Explained Simply: IS NULL, COALESCE and the common traps.
- SQL String Functions Explained Simply: trim, split and join text.
- 25 SQL Interview Questions for Beginners: test yourself with real interview questions and answers.
- The 10 Best SQL and Database Books: our picks from beginner to advanced.