SQL for Beginners: A Complete Guide to Querying Databases (With Practice Examples)

7 min readPublished 17 November 2026
3D illustration of rising blocks for the guide: SQL for Beginners: A Complete Guide to Querying Databases (With Practice Examples)
In this guide
  1. What Is SQL?
  2. Who Uses SQL?
  3. Understanding Tables, Rows and Columns
  4. How to Practise SQL for Free
  5. Your First Command: SELECT
  6. Filtering With WHERE
  7. Sorting With ORDER BY
  8. Limiting Results
  9. Calculations and Aliases
  10. Summarizing Data With Aggregate Functions
  11. Grouping With GROUP BY
  12. Combining Tables With JOIN
  13. Changing Data: INSERT, UPDATE and DELETE
  14. Creating Tables
  15. Subqueries: A Query Inside a Query
  16. Handy Functions Worth Knowing
  17. The Order SQL Reads Your Query
  18. Common Beginner Mistakes
  19. Practice Exercises
  20. A 4-Week Learning Plan
  21. Project Ideas
  22. What to Learn Next
  23. Frequently Asked Questions
  24. 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, NOT
  • IN for a list of values
  • BETWEEN for a range
  • LIKE for pattern matching
  • IS NULL to 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 rows
  • SUM() adds values
  • AVG() finds the average
  • MIN() and MAX() 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 text
  • ROUND() for numbers
  • COALESCE(value, replacement) to replace empty (NULL) values
  • CASE WHEN for 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 = (use IS 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:

  1. List all students from India.
  2. Show the three highest scores.
  3. Find the average score for each country.
  4. Count how many students scored above 70.
  5. List students whose names contain the letter “a.”
  6. 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.

Share this guideTelegramFacebook

Keep reading

Follow us on Telegram and WhatsAppGet new free guides and tool updates straight to your phone.

Share Article:

Considered an invitation do introduced sufficient understood instrument it. Of decisively friendship in as collecting at. No affixed be husband ye females brother garrets proceed. Least child who seven happy yet balls young. Discovery sweetness principle discourse shameless bed one excellent. Sentiments of surrounded friendship dispatched connection is he. Me or produce besides hastily up as pleased. 

Leave a Reply

Your email address will not be published. Required fields are marked *

Premier League: latest results
Newcastle2
Arsenal2
Sat 21 Nov · HT 0-1
Chelsea1
Leeds United4
Sat 21 Nov · HT 1-1
Aston Villa0
Sunderland0
Sat 21 Nov · HT 0-0
Bournemouth2
Nottingham0
Sat 21 Nov · HT 2-0
Tottenham2
Ipswich Town0
Sat 21 Nov · HT 1-0
Coventry City3
Crystal Palace2
Sat 21 Nov · HT 2-2
Man City1
Fulham1
Sat 21 Nov · HT 0-1
Man United4
Aston Villa4
Sun 8 Nov · HT 2-2

Sponsored

Sponsored

Proton: privacy in one account

Private email, a VPN, encrypted Drive storage for your files and a crypto wallet. Proton offers free plans for Mail, VPN, Drive and Wallet. Check current limits on its website.

Get Proton
Premier League: next fixtures
Hull City
Brighton Hove
Sun 22 Nov, 14:00 UTC
Liverpool
Man United
Sun 22 Nov, 16:30 UTC
Brentford
Everton
Mon 23 Nov, 20:00 UTC
Nottingham
Chelsea
Fri 27 Nov, 20:00 UTC
Leeds United
Coventry City
Sat 28 Nov, 15:00 UTC
Other leagues: next fixtures
La Liga
Barça
Villarreal
Sun 22 Nov, 13:00 UTC
Santander
Real Sociedad
Sun 22 Nov, 15:15 UTC
Osasuna
Málaga
Sun 22 Nov, 17:30 UTC
Serie A
Juventus
Venezia FC
Sun 22 Nov, 11:30 UTC
Bologna
Udinese
Sun 22 Nov, 14:00 UTC
Sassuolo
Genoa
Sun 22 Nov, 14:00 UTC
Bundesliga
Augsburg
Mainz
Sun 22 Nov, 14:30 UTC
Bremen
HSV
Sun 22 Nov, 16:30 UTC
Bremen
M'gladbach
Fri 27 Nov, 19:30 UTC
Ligue 1
Paris FC
Angers SCO
Sun 22 Nov, 14:00 UTC
Lorient
Stade Rennais
Sun 22 Nov, 16:15 UTC
Marseille
Le Mans
Sun 22 Nov, 19:45 UTC

Sponsored

Need a separate US number for sign-ups?

According to its website, Getatext provides US phone numbers for receiving SMS and verification codes. Check availability and terms, and always follow each site's rules.

Visit Getatext

Follow us on Telegram and WhatsApp

Get new free guides and tool updates from Aje5star straight to your phone.

Join on Telegram
Join on WhatsApp

Sponsored

Build a website or app with AI

Lovable lets you describe what you want and build it with an AI assistant, with no coding needed to get started. Check its current plans before you sign up.

Try Lovable
Join Our Family!!!

Sponsored

Recent Posts

  • All Post
  • AI & Productivity
  • AI Tools
  • AI Tools & Technology
  • Apps
  • Beauty
  • Blogging & SEO
  • Business Ideas
  • Career
  • Career & Digital Skills
  • Crypto & Finance
  • Cybersecurity
  • Cybersecurity & Technology
  • Digital Marketing
  • Digital Products
  • Education
  • Education & Technology
  • Entertainment
  • Financial
  • Financial Freedom
  • Freedom
  • Growth Strategy
  • Health
  • Learn Today
  • Lifestyle
  • Make Money Online
  • Marketing
  • Money
  • Music
  • Personal Development
  • Personal Finance
  • Photography
  • Productivity
  • Skills
  • Sports News
  • Tech Troubleshooting
  • Technology
  • Technology & Productivity
  • Technology & Tutorials
  • Travel
  • Wellbeing
  • WordPress
  • WordPress & Web Development
Edit Template

About

Recent Post

  • All Post
  • AI & Productivity
  • AI Tools
  • AI Tools & Technology
  • Apps
  • Beauty
  • Blogging & SEO
  • Business Ideas
  • Career
  • Career & Digital Skills
  • Crypto & Finance
  • Cybersecurity
  • Cybersecurity & Technology
  • Digital Marketing
  • Digital Products
  • Education
  • Education & Technology
  • Entertainment
  • Financial
  • Financial Freedom
  • Freedom
  • Growth Strategy
  • Health
  • Learn Today
  • Lifestyle
  • Make Money Online
  • Marketing
  • Money
  • Music
  • Personal Development
  • Personal Finance
  • Photography
  • Productivity
  • Skills
  • Sports News
  • Tech Troubleshooting
  • Technology
  • Technology & Productivity
  • Technology & Tutorials
  • Travel
  • Wellbeing
  • WordPress
  • WordPress & Web Development

© 2023-2025 Created by Aje5star.com