What Is SQL?
SQL (Structured Query Language) is the standard language for interacting with relational databases. Pronounced "sequel" or "S-Q-L", it is declarative — you describe what data you want, and the engine decides how to find it. Nearly every application that stores structured data uses SQL under the hood.
The One-Line Definition
SQL is a domain-specific language standardised by ANSI/ISO for defining, querying, and controlling data in relational database management systems (RDBMS) such as PostgreSQL, MySQL, SQLite, SQL Server, and Oracle.
A Basic Query
SELECT u.id, u.name, COUNT(o.id) AS order_count FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.created_at >= '2024-01-01' GROUP BY u.id, u.name HAVING COUNT(o.id) > 0 ORDER BY order_count DESC LIMIT 10;
DDL, DML, DCL, TCL
CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEXDefine and modify schema structure.
SELECT, INSERT, UPDATE, DELETE, MERGERead and write rows.
GRANT, REVOKEManage user permissions and access.
BEGIN, COMMIT, ROLLBACK, SAVEPOINTControl multi-statement transactions.
Query Anatomy
SELECTChoose which columns to return. Use * for all columns or list specific ones.FROMSpecify the base table (or subquery) to read from.JOIN … ONCombine rows from a second table using a key relationship.WHEREFilter rows before grouping. Cannot reference aggregate functions.GROUP BYCollapse multiple rows into groups for aggregation (COUNT, SUM, AVG…).HAVINGFilter groups after aggregation. Can reference aggregate functions.ORDER BYSort the result set. ASC (default) or DESC.LIMIT / TOPReturn only the first N rows. Syntax varies by database.JOIN Types
INNER JOINOnly rows with a match in both tables.LEFT JOINAll rows from the left table; NULLs for unmatched right rows.RIGHT JOINAll rows from the right table; NULLs for unmatched left rows.FULL OUTER JOINAll rows from both tables; NULLs where no match.CROSS JOINCartesian product — every left row paired with every right row.SELF JOINA table joined to itself, typically to find hierarchical relationships.Format SQL Now
SQL Formatter → — indent clauses, uppercase keywords, align columns. All client-side.
Frequently Asked Questions
What is the difference between DDL, DML, and DCL?
DDL (CREATE, ALTER, DROP) defines schema. DML (SELECT, INSERT, UPDATE, DELETE) works with data. DCL (GRANT, REVOKE) manages permissions. TCL (COMMIT, ROLLBACK) controls transactions.
How do SQL JOINs work?
A JOIN combines rows from two tables based on a related column. INNER JOIN returns only matches. LEFT JOIN returns all left rows plus matched right rows (NULLs where no match).
What is the difference between WHERE and HAVING?
WHERE filters individual rows before grouping. HAVING filters groups after aggregation and can reference aggregate functions like COUNT() or SUM().
How do I format SQL online?
Paste your query into SmartDevBox SQL Formatter. It indents clauses and uppercases keywords instantly, all in the browser.