SQL for Complete Beginners: Your First Queries Explained Simply

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.

Diagram labelling the SELECT, FROM, WHERE and ORDER BY parts of a SQL query

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:

idnameemailcountry
1Sara Ahmedsara@email.comEgypt
2John Smithjohn@email.comUK
3Mei Linmei@email.comChina
4Carlos Riveracarlos@email.comMexico
5Aisha Nooraisha@email.comEgypt

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:

nameemail
Sara Ahmedsara@email.com
John Smithjohn@email.com
Mei Linmei@email.com
Carlos Riveracarlos@email.com
Aisha Nooraisha@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:

idnameemailcountry
1Sara Ahmedsara@email.comEgypt
5Aisha Nooraisha@email.comEgypt

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:

OperatorMeaningExample
=equalsWHERE country = 'Egypt'
<> or !=not equalWHERE country <> 'UK'
> / <greater / less thanWHERE id > 3
>= / <=greater / less than or equalWHERE id <= 2
LIKEmatches a text patternWHERE 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):

countrycount
Egypt2
UK1
China1
Mexico1

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:

countrytotal_customers
Egypt2
China1
Mexico1
UK1

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.

  1. Show the name and country of every customer.
  2. Show the customers who are not from Egypt, sorted by name.
  3. How many customers are from the UK?
  4. Find the customers whose name contains the letters “ar”.
  5. Show each country that has more than one customer. (Hint: look up HAVING in 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 is NULL, and you check for it with IS NULL. = NULL never matches anything. NULL in SQL Explained Simply explains why.
  • Expecting a fixed order without ORDER BY. No ORDER BY means no promise about the order.
  • Using SELECT * everywhere. Fine for exploring, but list your columns in anything you keep.
  • Mixing up WHERE and HAVING. WHERE filters rows before they’re grouped. HAVING filters the groups after GROUP BY, like “countries with more than one customer” in question 5.

Quick Recap

CommandWhat it doesExample
SELECTReads columns from a tableSELECT name, email FROM customers
WHEREKeeps only matching rowsWHERE country = 'Egypt'
ORDER BYSorts the resultORDER BY name ASC
COUNT(*)Counts rowsSELECT COUNT(*) FROM customers
GROUP BYMakes one row per groupGROUP BY country
ASGives a column a readable nameCOUNT(*) AS total_customers
HAVINGFilters groupsHAVING 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:

  1. WHERE, ORDER BY and LIMIT: combine conditions, get the “top 5” and page through results.
  2. DISTINCT and aliases: remove duplicates and name your columns.
  3. GROUP BY and aggregate functions: SUM, AVG, MIN and MAX per group.
  4. SQL JOINs: connect two tables, the most important idea after this one.
  5. 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

Scroll to Top