Articles

What Is SQL? The Language of Databases, Explained

SQL is the standard language for querying and managing relational databases. Learn the core statements, how joins work, and when SQL is the right tool.

Chisato Chisato · · 3 min read
Stacked database cylinders

SQL — Structured Query Language — is the standard language for working with relational databases. You use it to create tables, insert data, retrieve records, and express relationships between them. Nearly every major database system supports it: PostgreSQL, MySQL, SQLite, SQL Server, and many others. If you work with data in any capacity, you will encounter SQL.

The key idea is that SQL is declarative: you describe the result you want, not the steps to get there. “Give me all orders placed in the last 30 days, sorted by total amount” — the database figures out how to execute that efficiently.

Core statements

SQL breaks down into a handful of statement types that map directly to operations on data.

SELECT retrieves rows from one or more tables:

SELECT name, email
FROM users
WHERE created_at > '2026-01-01'
ORDER BY name ASC;

INSERT adds new rows:

INSERT INTO users (name, email)
VALUES ('Chisato', 'chisato@example.com');

UPDATE modifies existing rows:

UPDATE users
SET email = 'new@example.com'
WHERE id = 42;

DELETE removes rows:

DELETE FROM users
WHERE last_login < '2025-01-01';

These four — often called CRUD (Create, Read, Update, Delete) — cover the vast majority of day-to-day SQL.

Tables and relationships

Data in a relational database lives in tables. Each table has named columns with defined types (TEXT, INTEGER, TIMESTAMPTZ, etc.) and rows of actual data. Tables connect to each other through foreign keys — a column in one table that references the primary key of another.

Consider a small schema:

CREATE TABLE customers (
  id    SERIAL PRIMARY KEY,
  name  TEXT NOT NULL
);

CREATE TABLE orders (
  id          SERIAL PRIMARY KEY,
  customer_id INT REFERENCES customers(id),
  total       NUMERIC(10, 2),
  placed_at   TIMESTAMPTZ DEFAULT now()
);

Now you can join them. A JOIN combines rows from two tables based on a matching condition:

SELECT customers.name, orders.total, orders.placed_at
FROM orders
JOIN customers ON orders.customer_id = customers.id
WHERE orders.total > 100
ORDER BY orders.placed_at DESC;

This returns each qualifying order alongside the customer’s name — without duplicating the customer record on every order row.

Aggregations and grouping

SQL can summarize data with aggregate functions like COUNT, SUM, AVG, MIN, and MAX. The GROUP BY clause organizes rows into groups before the aggregation runs:

SELECT customers.name, COUNT(orders.id) AS order_count
FROM customers
LEFT JOIN orders ON orders.customer_id = customers.id
GROUP BY customers.name
ORDER BY order_count DESC;

This query returns each customer and how many orders they have placed. The LEFT JOIN ensures customers with zero orders still appear in the results.

SQL vs NoSQL

SQL and NoSQL are not rivals so much as different tools for different shapes of data.

SQL (relational)NoSQL
StructureTables with defined schemasDocuments, key-value, graph, column-family
RelationshipsJoins and foreign keysUsually denormalized or application-level
TransactionsStrong ACID guaranteesVaries widely
Query languageStandard SQLDatabase-specific API or query language
Good forStructured data with clear relationshipsFlexible schemas, high write throughput, specific access patterns

A well-structured application often uses both: a relational database like PostgreSQL for the canonical source of truth, and something like Redis for caching or ephemeral data. The choice between SQL and NoSQL is rarely permanent — it depends on the access patterns and consistency requirements of each piece of data.

As data moves closer to users and infrastructure becomes more distributed, it is also worth understanding what edge databases offer on top of or alongside traditional SQL engines.

The takeaway

SQL has been the standard language for relational data since the 1970s because the underlying model — tables, rows, columns, and explicit relationships — maps well onto an enormous range of real problems. The syntax is readable, the semantics are well-defined, and the skills transfer across databases and tools. Learning SQL is one of the highest-leverage things you can do as a developer or data practitioner.

The Lycoris Team The Lycoris Team · · 6 min read

How to Read a Postgres EXPLAIN ANALYZE Query Plan

A step-by-step guide to running EXPLAIN ANALYZE in PostgreSQL and reading the query plan it returns — node types, costs, and where the real time went.

#Databases #SQL #Performance
The Lycoris Team The Lycoris Team · · 5 min read

What Is a Database Trigger?

A database trigger is a procedure that runs automatically on an insert, update, or delete — enforcing rules the application layer can't guarantee.

#Databases #SQL #Backend