SQL
You describe the answer you want; the database decides how to get it.
- First released
- 1974 (standardized 1986)
- Created by
- Donald Chamberlin and Raymond Boyce, at IBM
- Typing
- Declarative, with a static schema and typed columns
- File extensions
- .sql
What it is for
Ask a question of structured data and the answer is almost certainly SQL. It has held that position for fifty years against repeated attempts to replace it. What sets it apart is that it is declarative. You state what you want and a query planner works out how: which index to use, which join order is cheapest, whether to scan or seek. You describe a result, not a procedure.
That indirection is the whole bargain. It is why the same query keeps working as the data grows and the indexes change. It is also why the skill separating competent SQL from good SQL is knowing what the planner will do with what you wrote. EXPLAIN is the tool that turns guesswork into engineering.
The NoSQL wave of the 2010s argued relational databases would not scale. A decade later the industry mostly concluded it wanted transactions and joins after all. SQL absorbed the competition's better ideas along the way, picking up JSON columns, window functions and full-text search, and now turns up in data warehouses, analytics engines and stream processors with no traditional database anywhere in sight.
Where it came from
Edgar Codd published the relational model at IBM in 1970. Donald Chamberlin and Raymond Boyce built SEQUEL on top of it in 1974, aiming for something more approachable than the relational algebra underneath. The name was shortened to SQL for trademark reasons. IBM's System R was the first implementation, and Oracle beat IBM to a commercial release in 1979.
ANSI standardized it in 1986 and ISO in 1987. The standard has grown steadily since. SQL-92 is still the version most dialects measure themselves against, with recursive queries arriving in SQL:1999, window functions in SQL:2003, and JSON later.
None of that eliminated dialects. Every engine has its own extensions, its own date handling and its own opinions, so SQL is best understood as a family of closely related languages. The content here is written and verified against SQLite, which is both the most widely deployed engine in the world and the easiest to check against.
What it is like to type
SQL is the odd one out. Keywords are conventionally uppercase, so you spend runs of characters on shift that no other language asks for. Long identifiers, dotted table.column references and deeply nested parentheses in subqueries make it a test of sustained accuracy rather than speed.
116 steps across 6 tours, from the basics to complete programs.
The tours
- Language basicsSELECT, and everything immediately around it. 23 steps.
- Joins & aggregationWhere SQL starts being worth learning properly. 22 steps.
- Analytics & reportingThe tools for questions that do not fit in a single flat query. 24 steps.
- Schema & constraintsDesigning the schema rather than querying it. 16 steps.
- Plans & performanceReading EXPLAIN, which is the difference between guessing and knowing. 17 steps.
- JSON & searchSQL absorbed the document databases' better ideas rather than losing to them. 14 steps.
Official documentation
- SQLite SQL syntax
- SQLite query planner
- PostgreSQL SQL reference
- MySQL reference manual
- Use The Index, Luke