Databases
SQL
SQL (Structured Query Language) is the standard language for defining, querying and modifying data held in relational databases.
Updated 12 Aug 2026
Declaring what you want
SQL is declarative: you describe the result you want and the database's query planner decides how to produce it. That separation is why the same query can run unchanged as a table grows from a thousand rows to a hundred million — only the plan changes.
The families of statements
| Group | Statements | Purpose |
|---|---|---|
| DQL | SELECT | Read data |
| DML | INSERT, UPDATE, DELETE | Change rows |
| DDL | CREATE, ALTER, DROP | Define structure |
| DCL | GRANT, REVOKE | Control access |
| TCL | BEGIN, COMMIT, ROLLBACK | Group work into transactions |
How a SELECT is evaluated
- 1FROM and JOIN assemble the working set of rows
- 2WHERE filters individual rows
- 3GROUP BY collapses rows into groups
- 4HAVING filters those groups
- 5SELECT computes the output columns
- 6ORDER BY sorts, then LIMIT trims
Because SELECT runs after WHERE, a column alias defined in the SELECT list cannot be used in the WHERE clause — repeat the expression or wrap the query.
Readable SQL
Long queries become unreviewable when everything sits on one line. Put each clause on its own line, indent joins and conditions consistently, name every join condition explicitly, and avoid SELECT * in application code so a new column cannot silently change behaviour.
SQL Formatter
Paste a query to reindent and normalise keywords instantly.
Characteristics
- Declarative — describes the result, not the algorithm
- Set-based: operations apply to rows in bulk
- Standardised by ANSI, with dialect differences per engine
- Transactional, offering atomic multi-statement changes
Common uses
- Application data access in relational databases
- Reporting, dashboards and business analytics
- Data migrations and schema management
- ETL pipelines and warehouse transformations
Advantages
- One language works across most relational engines
- The planner optimises execution as data grows
- Transactions guarantee consistency across multiple changes
- Decades of tooling, documentation and expertise
Limitations
- Dialect differences complicate portability
- Poorly written queries can be catastrophically slow
- Awkward for hierarchical or graph-shaped data
- String-concatenated queries invite SQL injection
Examples
SELECT c.country,
COUNT(*) AS orders,
SUM(o.total) AS revenue
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.created_at >= '2026-01-01'
GROUP BY c.country
HAVING COUNT(*) > 25
ORDER BY revenue DESC
LIMIT 10;Frequently asked questions
What is SQL used for?
Storing, querying and modifying structured data in relational databases, plus reporting and analytics on top of it.
Is SQL a programming language?
It is a domain-specific declarative language. Procedural extensions such as PL/pgSQL add loops and variables.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping; HAVING filters the groups produced by GROUP BY.
What is SQL injection?
An attack where user input is concatenated into a query and executed as code. Use parameterised statements to prevent it.
SQL or NoSQL?
SQL suits related, consistent data with ad-hoc queries; NoSQL suits flexible schemas and very high write throughput.
Related terms
CSV
CSV (Comma-Separated Values) is a plain-text table format where each line is a row and each field is separated by a delimiter, usually a comma.
JSON
JSON is a lightweight text-based data format commonly used to exchange structured data between applications and APIs.
Regex
A regular expression (regex) is a compact pattern language for finding, validating and replacing text that matches a described shape rather than a fixed string.
API
An API (Application Programming Interface) is a defined contract that lets one piece of software request data or actions from another without knowing how it works internally.
XML
XML (Extensible Markup Language) is a text format that describes data using nested, self-labelled tags, designed for documents and long-lived system-to-system messaging.
Base64
Base64 is an encoding scheme that represents binary data using 64 printable ASCII characters so it can travel safely through text-only channels.
Related tools
Related guides
How to Format SQL for Readable, Reviewable Queries
A practical SQL formatting guide: keyword casing, indentation, join and CTE layout, comma placement, and how consistent formatting makes reviews and debugging faster.
What Is JSON? A Plain-English Guide
JSON explained without jargon: what it is, how the syntax works, which data types it supports, where it is used and how it differs from JavaScript objects.
How to Format JSON (Beautify, Indent and Minify)
Learn how JSON formatting works, see a before-and-after example, fix the errors that block beautifying, and format JSON online in your browser without uploading a file.
Why Does Compressing an Image Make It Bigger?
When image compression increases file size: re-encoding optimized JPEGs, PNG for photos, quality/format mismatches, and Max quality with no downsampling. How Image Compressor warns instead of faking a win — and what to try next.