Blog

Learn SQL

One language to ask any database. Start with a small students table on your computer, learn the core queries step by step, then practise on real data.

In shortLearn SQL from scratch with real examples: SELECT, WHERE, GROUP BY and JOIN on a students table, plus a 6-week practice plan and free official sources.
Learn SQL

Learning SQL is one of the fastest-paying technical skills for a student: a short language whose basics take weeks, and that you need in computer science, information systems, data analysis, business and even research. Every app you use stores its data in a database, and SQL is how you ask that database questions. In this guide you build a small students table on your computer, write the core queries with real examples, then follow a six-week practice plan.

What is SQL and why does everyone ask for it?

SQL stands for Structured Query Language, a language for working with relational databases: data lives in tables, each table has columns and rows, and tables link to each other. Systems such as PostgreSQL, MySQL, SQLite and SQL Server all understand SQL, with small differences in the details. What you learn on one system carries over to the rest.

Your majorWhy you need SQL
Computer science and software engineeringEvery web or mobile app needs a database, and your graduation project likely does too
Information systemsDesigning and querying databases is a core part of the courses
Data analysis and statisticsMost company data sits in databases, and SQL is the first tool to pull it
Business, finance and marketingSales and customer reports start with a query, and knowing it saves you waiting on others
Comparison card of the guide table

Set up in five minutes

The easiest start is SQLite. According to its official site, it is a complete database library in a single file with no server and no configuration. Install a free tool that opens SQLite files, or use the sqlite3 command line, and create a new file. Then paste this code to build a small students table:

Create a table and add data
CREATE TABLE students (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  major TEXT,
  gpa REAL,
  city TEXT
);

INSERT INTO students (name, major, gpa, city) VALUES
  ('Sara', 'Computer Science', 4.6, 'Jeddah'),
  ('Faisal', 'Accounting', 3.9, 'Riyadh'),
  ('Noura', 'Computer Science', 4.1, 'Riyadh'),
  ('Omar', 'Nursing', 4.8, 'Jeddah'),
  ('Lama', 'Accounting', 3.2, 'Dammam');

The core queries

These queries cover most of what you will write in your first month. Run each one and predict the result before you see it, because that is the fastest way to understand the language:

Select, filter and sort
-- every student
SELECT * FROM students;

-- computer science students only
SELECT name, gpa
FROM students
WHERE major = 'Computer Science';

-- highest GPAs first
SELECT name, gpa
FROM students
ORDER BY gpa DESC
LIMIT 3;

SELECT picks the columns, FROM picks the table, WHERE filters the rows, ORDER BY sorts and LIMIT sets how many. You can combine conditions with AND and OR, and use LIKE to search text.

Grouping
-- average GPA and number of students per major
SELECT major,
       COUNT(*) AS students,
       ROUND(AVG(gpa), 2) AS avg_gpa
FROM students
GROUP BY major
HAVING COUNT(*) >= 2
ORDER BY avg_gpa DESC;

GROUP BY gathers similar rows, and functions such as COUNT, AVG, SUM and MAX compute over each group. The key difference: WHERE filters rows before grouping, and HAVING filters groups after it.

Linking tables with JOIN

In a real database you do not put everything in one table. Students go in one table, courses in another, and enrolments in a third that links them. This is where JOIN shows its power:

JOIN two tables
CREATE TABLE enrollments (
  student_id INTEGER REFERENCES students(id),
  course TEXT,
  grade INTEGER
);

INSERT INTO enrollments VALUES
  (1, 'Databases', 95), (1, 'Algorithms', 88),
  (3, 'Databases', 79), (4, 'Anatomy', 97);

SELECT s.name, e.course, e.grade
FROM students s
JOIN enrollments e ON e.student_id = s.id
WHERE e.course = 'Databases';

A plain JOIN returns only rows that match in both tables. A LEFT JOIN returns every student, even those with no enrolment, and their enrolment columns show as empty (NULL). Try both and compare.

A six-week plan

  1. Week 1: tables and selecting

    CREATE TABLE, INSERT, SELECT, WHERE and ORDER BY on the students table. Write twenty queries yourself.

  2. Week 2: grouping

    COUNT, AVG, SUM, GROUP BY and HAVING. Ask questions about your data: which city has the highest average?

  3. Week 3: JOIN

    Design three linked tables for a topic you know, such as a library or a small shop, and write queries that join them.

  4. Week 4: changes and constraints

    UPDATE, DELETE, primary and foreign keys and NOT NULL. Learn why you need WHERE before any DELETE.

  5. Week 5: real data

    Finish the free Kaggle Intro to SQL course, which gives a completion certificate and uses real datasets.

  6. Week 6: a small project

    Design a database for an app you like, write ten queries that answer useful questions, and push it to GitHub with a README.

5-step flow: Week 1: tables and selecting / Week 2: grouping / Week 3: JOIN / Week 4: changes and constraints / Week 5: real data

Free official sources

Let AI coach you

Instead of letting it write the query, ask it for exercises on your table and to correct your attempts. Try this with ChatGPT or Gemini:

SQL coach
I am learning SQL. Here is my table: students(id, name, major, gpa, city) and enrollments(student_id, course, grade). Give me 5 practice questions in plain English, from easy to hard, one at a time. Wait for my query, then tell me if it is correct, show the result it would return, and explain any mistake without rewriting the whole query.
  • JetBrains: JetBrains offers JetBrains Student Pack to university students in Saudi Arabia for free.
  • GitHub: GitHub offers GitHub Student Developer Pack to university students in Saudi Arabia for free.
  • Google AI: Google AI offers Google AI Plus free for a year to university students in Saudi Arabia.

Common mistakes

  • Running DELETE or UPDATE without WHERE, which changes every row. Write a SELECT with the same condition first and check the result.
  • Using = to compare with NULL. The correct form is IS NULL or IS NOT NULL.
  • Putting a condition on a COUNT result in WHERE instead of HAVING.
  • Using SELECT * in every query. Pick only the columns you need.
  • Keeping all data in one huge table instead of splitting it into linked tables.

SQL is the first step in the data analysis roadmap, and you need it with JavaScript when you build an app that stores user data. If you study computer science, also read AI for computer science students.

Questions

Where do I start learning SQL?

Start with SQLite on your computer because it needs no server and no setup, create a small table, then learn SELECT, WHERE, GROUP BY and JOIN in that order.

How long does it take to learn SQL basics?

At an hour a day, four to six weeks covers the core queries, grouping, joins and a small project. Advanced queries come later with practice.

Is SQL a programming language?

It is a query language built for databases. You do not build a full app with it alone, but it works with any programming language, such as Python and JavaScript.

Should I learn MySQL, PostgreSQL or SQLite?

The basics are the same in all three. Start with SQLite because it is simple, then move to PostgreSQL or MySQL when you build an app that runs on a server.

Do I need SQL for data analysis?

Yes. Most company data is stored in databases, and SQL is the first tool you use to pull data before analysing it.

Sources

  1. sqlite.org: sqlite.org/about.html
  2. sqlite.org: sqlite.org/lang.html
  3. postgresql.org: postgresql.org/docs/current/tutorial.html
  4. kaggle.com: kaggle.com/learn/intro-to-sql
  5. kaggle.com: kaggle.com/learn/advanced-sql

Hear when tiswa opens.

Join the free waitlist. We notify you at launch; then verify as a student and access the deals under their terms.

  • Free for good
  • No card
  • Takes a minute
Join the waitlist

More articles