Skip to editor content
learningsql.orglesson 1 of 25

Introduction to SQL

TL;DR — SQL (Structured Query Language) is the standard language for querying relational databases. You use SELECT to retrieve data, INSERT to add rows, UPDATE to change values, and DELETE to remove them. It runs on PostgreSQL, MySQL, SQLite, and most other databases with the same core syntax. This lesson walks through your first queries — no database install needed.

Welcome to your first lesson in SQL! In this introduction, we'll cover what SQL is, why it's essential for working with data, and how to write your first queries.

What is SQL?

SQL (Structured Query Language) is a powerful language designed for managing and manipulating data stored in relational databases. It's been the standard for database interaction for over 40 years and is used by millions of applications worldwide.

Key Features

Simple and Declarative

SQL lets you describe what data you want, not how to get it:

-- Get all users from the database
SELECT * FROM users;

Powerful Data Manipulation

SQL provides commands for creating, reading, updating, and deleting data:

-- Create a new table
CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    price DECIMAL(10, 2)
);

-- Insert data
INSERT INTO products (id, name, price) VALUES (1, 'Laptop', 999.99);

-- Query the data
SELECT * FROM products;

Universal Language

SQL works with most database systems including PostgreSQL, MySQL, SQLite, SQL Server, and Oracle. While each has slight variations, the core SQL syntax remains consistent.

Why Learn SQL?

  1. Data Access: Query and analyze data from any relational database
  2. Career Value: SQL is one of the most in-demand skills in tech
  3. Versatility: Used in web development, data science, analytics, and more
  4. Simplicity: Easy to learn with powerful capabilities

Your First Query

The simplest SQL query selects data without even needing a table:

-- Display a simple message
SELECT 'Hello, SQL!' AS message;

-- Perform calculations
SELECT 2 + 2 AS result;

-- Work with multiple columns
SELECT
    'SQL' AS language,
    2025 AS year,
    'Awesome' AS description;

Try these exercises:

  1. Change the message to include your name
  2. Try different mathematical operations (*, /, -)
  3. Add more columns to the SELECT statement
  4. Change the column aliases (the names after AS)

Interactive Playground

Practice what you've learned! Edit and run the SQL code below to experiment with your first database.

-- Create a simple table
CREATE TABLE students (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    age INTEGER,
    grade TEXT
);

-- Add some students
INSERT INTO students (id, name, age, grade) VALUES (1, 'Alice', 20, 'A');
INSERT INTO students (id, name, age, grade) VALUES (2, 'Bob', 22, 'B');
INSERT INTO students (id, name, age, grade) VALUES (3, 'Charlie', 21, 'A');

-- Query all students
SELECT * FROM students;

Try these exercises:

  1. Add yourself as a new student to the table
  2. Change the ages or grades of existing students
  3. Add a new column like "major" to the table schema
  4. Query only specific columns instead of using *

Pro Tip: SQL is not case-sensitive, but it's a common convention to write SQL keywords in UPPERCASE and table/column names in lowercase. This makes your queries easier to read!

Key Takeaways

  • SQL is a declarative language for managing and querying relational databases
  • Tables store data in rows and columns, similar to spreadsheets but with strict structure
  • SELECT * FROM table retrieves all data from a table
  • INSERT INTO adds new rows, and you define table structure with CREATE TABLE

Next Steps

Now that you understand what SQL is and how databases store data, it is time to write your first real queries. The next lesson covers the SELECT statement in depth — choosing specific columns, creating aliases, removing duplicates, and limiting results. SELECT is the foundation of everything you will do in SQL, so mastering it early pays dividends in every lesson that follows.

Keep exploring:

  • Continue learning → — work through all 25 SQL lessons, from SELECT basics to query optimization, right in your browser
  • SQL Playground — run queries against a live database right in your browser

Next lesson

Selecting Data

Master the SQL SELECT statement to retrieve specific data from your database. Learn column aliases, DISTINCT, LIMIT, and expressions.

20 min