SQL
SQL (Structured Query Language) is the standard language for managing and querying relational databases. It is used to create, read, update, and delete data in structured tables with defined schemas and relationships.
§ 1 Definition
SQL (pronounced S-Q-L or 'sequel') is the universal language of relational databases. Developed by Donald Chamberlin and Raymond Boyce at IBM in the 1970s, SQL was standardized by ANSI in 1986 and ISO in 1987. SQL operates on structured data organized into tables (rows and columns) with defined schemas and relationships expressed through foreign keys. SQL is declarative: you specify what data you want, not how to retrieve it. The database's query optimizer determines the execution plan. This abstraction is SQL's superpower. You can write the same SELECT statement against a 100-row SQLite database and a 100-billion-row PostgreSQL cluster, and both return the correct result. SQL consists of several sublanguages: DDL (Data Definition Language: CREATE, ALTER, DROP for schema), DML (Data Manipulation Language: SELECT, INSERT, UPDATE, DELETE for data), DCL (Data Control Language: GRANT, REVOKE for permissions), and TCL (Transaction Control Language: BEGIN, COMMIT, ROLLBACK). Despite being 50 years old, SQL remains the most important data language. Every developer should understand SELECT, JOIN, WHERE, GROUP BY, and subqueries.
§ 2 Core SQL Operations
The four fundamental operations are CRUD: SELECT (read), INSERT (create), UPDATE (modify), and DELETE (remove). SELECT queries can filter with WHERE, sort with ORDER BY, limit results with LIMIT/OFFSET, and aggregate with GROUP BY and HAVING. JOIN operations combine data from multiple tables: INNER JOIN (matching rows only), LEFT JOIN (all left-side rows), RIGHT JOIN (all right-side rows), and FULL JOIN (all rows from both sides). Subqueries nest queries inside other queries. Common Table Expressions (CTEs) with WITH create temporary result sets for complex queries. Window functions (ROW_NUMBER, RANK, LAG, LEAD) perform calculations across sets of rows related to the current row. Mastering these operations covers 95% of SQL usage in web applications.
§ 3 SQL Performance: Indexing and Query Planning
SQL performance depends almost entirely on indexing. An index is a data structure (typically a B-tree) that speeds up row lookups by column values. Without an index, the database performs a sequential scan (reading every row). With an index, it navigates directly to the matching rows. Indexes speed up SELECT, WHERE, JOIN, and ORDER BY but slow down INSERT and UPDATE (because the index must be updated). The EXPLAIN or EXPLAIN ANALYZE command reveals how the database executes a query: which indexes it uses, how many rows it scans, and where the bottlenecks are. Understanding query plans is the skill that separates competent SQL users from experts. Common performance traps: missing indexes on foreign keys, using functions in WHERE clauses (WHERE YEAR(created_at) = 2024 instead of WHERE created_at >= '2024-01-01'), and SELECT * (fetching unnecessary columns).
§ 4 SQL Dialects: PostgreSQL, MySQL, SQLite, SQL Server
SQL is standardized, but every database implements it slightly differently. PostgreSQL is the gold standard: standards-compliant, extensible, with excellent JSON support, full-text search, and custom types. MySQL/MariaDB is widely used, fast for read-heavy workloads, but historically weaker on ACID compliance and optimizer quality. SQLite is an embedded, file-based database, perfect for development, mobile apps, and edge cases. SQL Server is Microsoft's enterprise offering with deep Windows integration. The differences matter for migrating between databases. Stick with standard SQL where possible and check compatibility for database-specific features (PostgreSQL's RETURNING, MySQL's ON DUPLICATE KEY UPDATE, SQLite's AUTOINCREMENT behavior). PostgreSQL is recommended for new projects unless you have a specific reason to choose otherwise.
§ 5 Note
§ 6 In code
```sql
-- Find the top 3 authors by post count this year
SELECT
u.name,
COUNT(p.id) AS post_count,
MAX(p.created_at) AS last_post
FROM users u
JOIN posts p ON p.user_id = u.id
WHERE p.created_at >= '2026-01-01'
GROUP BY u.id, u.name
HAVING COUNT(p.id) > 0
ORDER BY post_count DESC
LIMIT 3;
-- Same query with a CTE
WITH yearly_posts AS (
SELECT user_id, COUNT(*) AS cnt, MAX(created_at) AS last_post
FROM posts
WHERE created_at >= '2026-01-01'
GROUP BY user_id
)
SELECT u.name, yp.cnt, yp.last_post
FROM users u
JOIN yearly_posts yp ON yp.user_id = u.id
ORDER BY yp.cnt DESC
LIMIT 3;
```§ 7 Common questions
- Q. Which SQL dialect should I learn?
- A. PostgreSQL. It is the most feature-rich, standards-compliant, and widely recommended for new projects. Skills transfer well to other SQL databases.
- Q. What is the difference between WHERE and HAVING?
- A. WHERE filters rows before aggregation. HAVING filters groups after aggregation. Use WHERE for individual row filters (WHERE status = 'active'). Use HAVING for aggregate conditions (HAVING COUNT(*) > 5).
- Q. Do I need to learn SQL if I use an ORM?
- A. Yes. ORMs generate SQL, but they often produce inefficient queries. You need to read and understand the SQL they generate to optimize performance and fix issues.
- SQL is the standard language for querying and managing relational databases, standardized since 1986.
- Declarative: you specify what data you want, not how to get it. The optimizer handles execution.
- Indexing is the most important factor in SQL performance. Use EXPLAIN ANALYZE to understand query plans.
- PostgreSQL is the recommended SQL database for new projects.
Atomic Glue designs and optimizes SQL databases for every web application we build. PostgreSQL is our standard database, and our team writes efficient SQL for everything from simple CRUD to complex reporting queries. We use EXPLAIN ANALYZE to optimize query plans, design indexing strategies, and structure schemas for performance. SQL expertise is a core part of our Web Development services. Get in touch to design your database layer.
Get in touchSQL (Structured Query Language) is the standard language for managing and querying relational databases. It is used to create, read, update, and delete data in structured tables with defined schemas and relationships.
Category: Backend (also: Software Engineering, Apis, Analytics)
Author: Atomic Glue Development Team
## Definition
SQL (pronounced S-Q-L or 'sequel') is the universal language of relational databases. Developed by Donald Chamberlin and Raymond Boyce at IBM in the 1970s, SQL was standardized by ANSI in 1986 and ISO in 1987. SQL operates on structured data organized into tables (rows and columns) with defined schemas and relationships expressed through foreign keys. SQL is declarative: you specify what data you want, not how to retrieve it. The database's query optimizer determines the execution plan. This abstraction is SQL's superpower. You can write the same SELECT statement against a 100-row SQLite database and a 100-billion-row PostgreSQL cluster, and both return the correct result. SQL consists of several sublanguages: DDL (Data Definition Language: CREATE, ALTER, DROP for schema), DML (Data Manipulation Language: SELECT, INSERT, UPDATE, DELETE for data), DCL (Data Control Language: GRANT, REVOKE for permissions), and TCL (Transaction Control Language: BEGIN, COMMIT, ROLLBACK). Despite being 50 years old, SQL remains the most important data language. Every developer should understand SELECT, JOIN, WHERE, GROUP BY, and subqueries.
## Core SQL Operations
The four fundamental operations are CRUD: SELECT (read), INSERT (create), UPDATE (modify), and DELETE (remove). SELECT queries can filter with WHERE, sort with ORDER BY, limit results with LIMIT/OFFSET, and aggregate with GROUP BY and HAVING. JOIN operations combine data from multiple tables: INNER JOIN (matching rows only), LEFT JOIN (all left-side rows), RIGHT JOIN (all right-side rows), and FULL JOIN (all rows from both sides). Subqueries nest queries inside other queries. Common Table Expressions (CTEs) with WITH create temporary result sets for complex queries. Window functions (ROW_NUMBER, RANK, LAG, LEAD) perform calculations across sets of rows related to the current row. Mastering these operations covers 95% of SQL usage in web applications.
## SQL Performance: Indexing and Query Planning
SQL performance depends almost entirely on indexing. An index is a data structure (typically a B-tree) that speeds up row lookups by column values. Without an index, the database performs a sequential scan (reading every row). With an index, it navigates directly to the matching rows. Indexes speed up SELECT, WHERE, JOIN, and ORDER BY but slow down INSERT and UPDATE (because the index must be updated). The EXPLAIN or EXPLAIN ANALYZE command reveals how the database executes a query: which indexes it uses, how many rows it scans, and where the bottlenecks are. Understanding query plans is the skill that separates competent SQL users from experts. Common performance traps: missing indexes on foreign keys, using functions in WHERE clauses (WHERE YEAR(created_at) = 2024 instead of WHERE created_at >= '2024-01-01'), and SELECT * (fetching unnecessary columns).
## SQL Dialects: PostgreSQL, MySQL, SQLite, SQL Server
SQL is standardized, but every database implements it slightly differently. PostgreSQL is the gold standard: standards-compliant, extensible, with excellent JSON support, full-text search, and custom types. MySQL/MariaDB is widely used, fast for read-heavy workloads, but historically weaker on ACID compliance and optimizer quality. SQLite is an embedded, file-based database, perfect for development, mobile apps, and edge cases. SQL Server is Microsoft's enterprise offering with deep Windows integration. The differences matter for migrating between databases. Stick with standard SQL where possible and check compatibility for database-specific features (PostgreSQL's RETURNING, MySQL's ON DUPLICATE KEY UPDATE, SQLite's AUTOINCREMENT behavior). PostgreSQL is recommended for new projects unless you have a specific reason to choose otherwise.
## Note
Common misunderstanding: SQL is a legacy technology being replaced by NoSQL. SQL has been the dominant data language for 50 years and is not going anywhere. NoSQL databases added valuable options for specific use cases, but SQL remains the default for transactional data. Even many NoSQL databases have added SQL-like query languages. Another misconception: ORMs eliminate the need to understand SQL. ORMs generate SQL from object-oriented code, but they often generate inefficient SQL. Every developer who works with databases needs to understand SQL to debug ORM-generated queries, optimize performance, and handle complex queries beyond the ORM's capabilities.
## In code
## Common questions Q: Which SQL dialect should I learn? A: PostgreSQL. It is the most feature-rich, standards-compliant, and widely recommended for new projects. Skills transfer well to other SQL databases. Q: What is the difference between WHERE and HAVING? A: WHERE filters rows before aggregation. HAVING filters groups after aggregation. Use WHERE for individual row filters (WHERE status = 'active'). Use HAVING for aggregate conditions (HAVING COUNT(*) > 5). Q: Do I need to learn SQL if I use an ORM? A: Yes. ORMs generate SQL, but they often produce inefficient queries. You need to read and understand the SQL they generate to optimize performance and fix issues.
## Key takeaways
- SQL is the standard language for querying and managing relational databases, standardized since 1986.
- Declarative: you specify what data you want, not how to get it. The optimizer handles execution.
- Indexing is the most important factor in SQL performance. Use EXPLAIN ANALYZE to understand query plans.
- PostgreSQL is the recommended SQL database for new projects.
## Related entries
- [Database](atomicglue.co/glossary/database)
- [NoSQL](atomicglue.co/glossary/nosql)
- [ORM](atomicglue.co/glossary/orm)
Last updated June 2026. Permalink: atomicglue.co/glossary/sql