Labs ICT
Pro Login

Get Started

Alright, let us actually get our hands dirty. The best way to learn SQL is to write SQL, so we are going to start right away.

For these tutorials, you can use our online SQL Compiler to run all the examples. It uses SQLite behind the scenes, which is perfect for learning.

Your First SQL Query

Let us start with the most famous SQL query of all time:

SELECT "Hello, World!" AS message;

Go ahead, type that into the SQL compiler and run it. You should see "Hello, World!" come back as a result. Congratulations, you just wrote your first SQL query!

I know it is simple, but do not underestimate it. Every complex SQL query you will ever write is built on this same foundation. You are SELECTing something and getting results back.

Setting Up a Practice Database

To really learn SQL, you need some data to play with. Here is a simple table we will use throughout this tutorial:

CREATE TABLE students (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  age INTEGER,
  city TEXT,
  score INTEGER
);

INSERT INTO students VALUES (1, 'Amina', 22, 'Kano', 85);
INSERT INTO students VALUES (2, 'Musa', 24, 'Lagos', 92);
INSERT INTO students VALUES (3, 'Fatima', 21, 'Abuja', 78);
INSERT INTO students VALUES (4, 'John', 23, 'Port Harcourt', 88);
INSERT INTO students VALUES (5, 'Zainab', 20, 'Kano', 95);

Copy and run this in the SQL compiler. It creates a table called students and puts some sample data in it. Do not worry about the CREATE TABLE part for now — we will cover that later. Just focus on having some data to query.

Check Your Data

Now that you have data, let us make sure it is there:

SELECT * FROM students;

This should show you all the rows in the students table. The asterisk * means "give me everything." You will use this a lot.