SQL is the domain-specific standard language used to query, manipulate, and manage relational database management systems (RDBMS).
SQL (Structured Query Language) is a domain-specific declarative language standardized by ANSI and ISO for querying, defining, and managing structured data within Relational Database Management Systems (RDBMS). SQL enables developers and data analysts to insert, filter, aggregate, update, and join relational tables across enterprise databases like PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server.
Format complex database queries and beautify queries with our privacy-first SQL Formatter tool or generate SQL tables from JSON with JSON to SQL.
| Specification | Details |
|---|---|
| First Introduced | 1974 (IBM System R by Donald Chamberlin & Raymond Boyce) |
| Official Standards | ANSI X3.135 / ISO/IEC 9075 (Latest: SQL:2023) |
| Execution Paradigm | Declarative (Specifies what data to retrieve, not how) |
| Core Dialects | PostgreSQL, MySQL, SQLite, T-SQL, PL/SQL, Snowflake, BigQuery |
| Underlying Mathematics | Relational Algebra and Tuple Relational Calculus (E. F. Codd) |
SQL statements are divided into five functional sub-languages:
| Sub-Language | Full Name | Primary Commands | Operational Purpose |
|---|---|---|---|
| DQL | Data Query Language | SELECT |
Queries and retrieves data records from tables. |
| DML | Data Manipulation Language | INSERT, UPDATE, DELETE, MERGE |
Modifies existing data rows within tables. |
| DDL | Data Definition Language | CREATE, ALTER, DROP, TRUNCATE |
Defines and alters relational schema structures. |
| DCL | Data Control Language | GRANT, REVOKE |
Manages user permissions, privileges, and access security. |
| TCL | Transaction Control Language | COMMIT, ROLLBACK, SAVEPOINT |
Manages ACID transactional consistency. |
While SQL queries are written starting with SELECT, database query planners evaluate clauses in a completely different logical order:
Written Order: Execution Order:
1. SELECT 1. FROM / JOIN (Identify tables and merge rows)
2. FROM / JOIN 2. WHERE (Filter individual rows)
3. WHERE 3. GROUP BY (Aggregate rows into buckets)
4. GROUP BY 4. HAVING (Filter aggregated buckets)
5. HAVING 5. SELECT (Evaluate expressions and window functions)
6. ORDER BY 6. DISTINCT (Deduplicate row results)
7. LIMIT / OFFSET 7. ORDER BY (Sort final rows)
8. LIMIT / OFFSET (Paginate result set)
Understanding this execution pipeline explains why column aliases declared in the SELECT clause cannot be referenced inside WHERE clauses.
SQL Injection (SQLi) remains one of the top OWASP vulnerabilities worldwide. It occurs when untrusted user input is directly concatenated into a dynamic SQL query string, allowing attackers to manipulate the query logic:
// ❌ HIGHLY VULNERABLE: Direct string interpolation
const query = `SELECT * FROM users WHERE email = '${userInput}' AND password = '${passwordHash}'`;
If an attacker enters ' OR '1'='1 for the email, the resulting SQL statement becomes:
SELECT * FROM users WHERE email = '' OR '1'='1' AND password = '...'
The query evaluates to TRUE for all rows, granting unauthorized authentication bypass.
Always use parameterized queries. Parameters are transmitted separately from SQL logic, making it impossible for input to be interpreted as executable code:
// ✅ SECURE: Parameterized query (PostgreSQL syntax)
const result = await db.query(
'SELECT id, name, email FROM users WHERE email = $1 AND is_active = $2',
[userInput, true]
);
SQL databases (relational) use predefined structured schemas, foreign keys, tables, and strict ACID transactions. They are optimal for complex relational data like financial transactions and ecommerce. NoSQL databases (like MongoDB or Redis) use flexible document, key-value, or graph models, optimizing for horizontal scaling and rapidly evolving unnested JSON structures.
WHERE and HAVING in SQL?WHERE filters individual rows before any aggregation or GROUP BY operations occur. HAVING filters aggregated row groups after the GROUP BY clause has been processed (for example: HAVING COUNT(*) > 5).
INNER JOIN, LEFT JOIN, and FULL JOIN differ?INNER JOIN: Returns only rows that match in both tables.LEFT JOIN: Returns all rows from the left table and matched rows from the right table (unmatched right columns return NULL).FULL OUTER JOIN: Returns all rows from both tables, filling missing fields with NULL.Unformatted single-line SQL queries are difficult to debug and review in pull requests. You can paste any query into our browser-based SQL Formatter tool to automatically indent keywords, clauses, and subqueries cleanly.
Free, browser-based utilities to test, generate, and inspect SQL (Structured Query Language) payloads directly.