
In this guide
- What Is SQL?
- Who Uses SQL?
- Understanding Tables, Rows and Columns
- How to Practise SQL for Free
- Your First Command: SELECT
- Filtering With WHERE
- Sorting With ORDER BY
- Limiting Results
- Calculations and Aliases
- Summarizing Data With Aggregate Functions
- Grouping With GROUP BY
- Combining Tables With JOIN
- Changing Data: INSERT, UPDATE and DELETE
- Creating Tables
- Subqueries: A Query Inside a Query
- Handy Functions Worth Knowing
- The Order SQL Reads Your Query
- Common Beginner Mistakes
- Practice Exercises
- A 4-Week Learning Plan
- Project Ideas
- What to Learn Next
- Frequently Asked Questions
- Final Thoughts
Almost every app, website and business stores its information in a database. Customer lists, orders, bank transactions, social media posts, school grades: all of it lives in tables that someone can search, filter and analyse. The language used to talk to those databases is SQL (Structured Query Language), and it is one of the most valuable and beginner-friendly skills in tech.
The best part is that SQL reads almost like plain English. In this guide you will learn what SQL is, how databases are organized, and how to write the queries you will use every day, with practice examples you can try for free.
What Is SQL?
SQL is a language for storing, retrieving, updating and managing data in relational databases. A relational database organizes information into tables, similar to spreadsheets, that can be linked to each other. Popular systems that use SQL include MySQL, PostgreSQL, SQLite, Microsoft SQL Server and Oracle. The core commands are very similar across all of them, with small differences in advanced features.
Who Uses SQL?
- Data analysts to answer business questions
- Software developers to build apps that store data
- Marketers and product managers to study customer behaviour
- Accountants and finance teams to pull reports
- Scientists and researchers to manage datasets
Even if you never become a full-time developer, SQL saves huge amounts of time compared with copying data around in spreadsheets.
Understanding Tables, Rows and Columns
Imagine a table called students:
| id | name | country | score |
|---|---|---|---|
| 1 | Amina | Morocco | 88 |
| 2 | Daniel | Kenya | 72 |
| 3 | Sofia | Spain | 95 |
| 4 | Ravi | India | 64 |
- Each column is a type of information (id, name, country, score).
- Each row is one record (one student).
- The primary key (here,
id) uniquely identifies each row.
How to Practise SQL for Free
You do not need to install anything big. Options include:
- Online SQL playgrounds that run in your browser, where you can create tables and test queries instantly.
- SQLite, a lightweight database that is free and easy to install.
- DB Browser for SQLite, a free visual tool.
- Free interactive SQL courses with built-in practice exercises.
Your First Command: SELECT
SELECT retrieves data. To see every column and row in a table:
SELECT * FROM students;
The asterisk means “all columns.” To choose specific columns:
SELECT name, score FROM students;
Notes: SQL keywords are usually written in capitals by convention (not required), and statements end with a semicolon.
Filtering With WHERE
WHERE limits the rows returned.
SELECT name, score
FROM students
WHERE score >= 80;
Common operators:
=equal,<>or!=not equal>,<,>=,<=AND,OR,NOTINfor a list of valuesBETWEENfor a rangeLIKEfor pattern matchingIS NULLto find missing values
Examples:
SELECT * FROM students WHERE country = 'Kenya';
SELECT * FROM students WHERE country IN ('Spain', 'India');
SELECT * FROM students WHERE score BETWEEN 70 AND 90;
SELECT * FROM students WHERE name LIKE 'S%';
Text values go inside single quotes. The % in LIKE means “any characters,” so 'S%' finds names starting with S.
Sorting With ORDER BY
SELECT name, score
FROM students
ORDER BY score DESC;
DESC sorts from highest to lowest, and ASC (the default) from lowest to highest. You can sort by several columns, separated by commas.
Limiting Results
To see only the top results:
SELECT name, score
FROM students
ORDER BY score DESC
LIMIT 3;
Note: some systems, such as SQL Server, use SELECT TOP 3 instead of LIMIT.
Calculations and Aliases
SELECT name, score, score / 100.0 AS percentage
FROM students;
The word AS gives a column a friendlier name, called an alias.
Summarizing Data With Aggregate Functions
Aggregate functions calculate a single result from many rows.
COUNT()counts rowsSUM()adds valuesAVG()finds the averageMIN()andMAX()find the smallest and largest
SELECT COUNT(*) AS total_students,
AVG(score) AS average_score,
MAX(score) AS top_score
FROM students;
Grouping With GROUP BY
GROUP BY splits data into groups and applies an aggregate function to each.
SELECT country, AVG(score) AS avg_score
FROM students
GROUP BY country;
To filter groups (rather than individual rows), use HAVING:
SELECT country, COUNT(*) AS num_students
FROM students
GROUP BY country
HAVING COUNT(*) > 1;
A handy memory trick: WHERE filters rows before grouping, HAVING filters groups after.
Combining Tables With JOIN
Real databases split information across tables to avoid repetition. Suppose there is a second table called courses:
| course_id | student_id | course_name |
|---|---|---|
| 101 | 1 | Biology |
| 102 | 3 | Maths |
| 103 | 3 | Physics |
The student_id column links to students.id. This is called a foreign key. To combine the two:
SELECT students.name, courses.course_name
FROM students
INNER JOIN courses
ON students.id = courses.student_id;
The main types of JOIN
- INNER JOIN: only rows that match in both tables.
- LEFT JOIN: all rows from the left table, plus matching rows from the right (empty where there is no match).
- RIGHT JOIN: all rows from the right table, plus matches from the left.
- FULL JOIN: all rows from both tables (not available in every system).
To find students with no courses, use a LEFT JOIN and filter for missing matches:
SELECT students.name
FROM students
LEFT JOIN courses ON students.id = courses.student_id
WHERE courses.course_id IS NULL;
Changing Data: INSERT, UPDATE and DELETE
INSERT adds new rows
INSERT INTO students (id, name, country, score)
VALUES (5, 'Lena', 'Germany', 81);
UPDATE modifies existing rows
UPDATE students
SET score = 90
WHERE name = 'Daniel';
DELETE removes rows
DELETE FROM students
WHERE id = 4;
Warning: always include a WHERE clause with UPDATE and DELETE. Without it, the command affects every row in the table. Test with a SELECT first, and take backups before changing important data.
Creating Tables
CREATE TABLE teachers (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
subject TEXT,
hired_date DATE
);
Common data types include integers, decimals, text (VARCHAR or TEXT), dates and booleans. Exact names vary slightly between systems.
Subqueries: A Query Inside a Query
Find students scoring above the average:
SELECT name, score
FROM students
WHERE score > (SELECT AVG(score) FROM students);
Handy Functions Worth Knowing
UPPER(),LOWER(),LENGTH()for textROUND()for numbersCOALESCE(value, replacement)to replace empty (NULL) valuesCASE WHENfor if-then logic:
SELECT name,
CASE
WHEN score >= 85 THEN 'Excellent'
WHEN score >= 70 THEN 'Good'
ELSE 'Needs improvement'
END AS grade
FROM students;
The Order SQL Reads Your Query
You write: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. But the database processes it in a different order: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT. Understanding this explains why you cannot always use a column alias inside WHERE.
Common Beginner Mistakes
- Forgetting the WHERE clause on UPDATE or DELETE
- Using double quotes for text instead of single quotes
- Comparing with NULL using
=(useIS NULL) - Selecting columns not included in GROUP BY
- Joining tables without the ON condition, creating a huge, wrong result
- Using
SELECT *on very large tables
Practice Exercises
Using the students table, try writing queries to:
- List all students from India.
- Show the three highest scores.
- Find the average score for each country.
- Count how many students scored above 70.
- List students whose names contain the letter “a.”
- Show each student’s name with their courses (JOIN).
A 4-Week Learning Plan
- Week 1: SELECT, WHERE, ORDER BY, LIMIT.
- Week 2: aggregate functions, GROUP BY, HAVING.
- Week 3: JOINs and table relationships.
- Week 4: INSERT, UPDATE, DELETE, CASE, subqueries, and a mini project with a real dataset.
Project Ideas
- Analyse a public dataset such as sales, movies or sports.
- Build a small library database with books, members and loans.
- Track personal expenses in SQLite and run monthly summaries.
What to Learn Next
- Window functions (ranking, running totals)
- Common Table Expressions (CTEs)
- Database design and normalization
- Indexes and query performance
- Connecting SQL with Python, Excel or business intelligence tools
Frequently Asked Questions
Is SQL a programming language?
It is a specialized query language for databases. It is not a general-purpose language like Python, but it is a real, in-demand skill.
How long does it take to learn SQL?
You can learn the basics in a few weeks of regular practice. Mastery of advanced topics takes longer.
Is SQL hard to learn?
Most people find it one of the easier technical skills because the syntax is readable and results are immediate.
Which database should I start with?
SQLite or PostgreSQL are great free options. The core skills transfer to the others.
Final Thoughts
SQL gives you the power to ask questions of data and get answers in seconds. Start with SELECT and WHERE today, practise on a free online playground, and build up to joins and grouping. With a few weeks of consistent practice, you will have a skill that opens doors in analytics, development and many other careers.




















































