This SQL cheat sheet summarises the core SQL statements for querying and changing data — SELECT, WHERE, JOIN, GROUP BY, INSERT, UPDATE, DELETE — plus common data types. Works with MySQL, PostgreSQL, SQL Server and SQLite.
Querying data
| Statement | What it does |
|---|
| SELECT * FROM table | Select all columns |
| SELECT col1, col2 FROM table | Select specific columns |
| WHERE price > 100 | Filter rows |
| ORDER BY col DESC | Sort results |
| LIMIT 10 | Limit number of rows |
| SELECT DISTINCT col | Unique values |
| WHERE name LIKE 'A%' | Pattern match |
Joins & grouping
| Statement | What it does |
|---|
| INNER JOIN b ON a.id=b.aid | Rows matching in both tables |
| LEFT JOIN b ON ... | All left rows + matches |
| GROUP BY col | Group rows |
| HAVING COUNT(*) > 1 | Filter groups |
| COUNT() / SUM() / AVG() | Aggregate functions |
Modifying data
| Statement | What it does |
|---|
| INSERT INTO t (a) VALUES (1) | Add a row |
| UPDATE t SET a=1 WHERE id=2 | Change rows |
| DELETE FROM t WHERE id=2 | Remove rows |
| CREATE TABLE t (...) | Create a table |
| ALTER TABLE t ADD col | Modify a table |
| DROP TABLE t | Delete a table |
Common data types
| Type | Use |
|---|
| INT | Whole numbers |
| DECIMAL(10,2) | Exact decimals (money) |
| VARCHAR(255) | Short text |
| TEXT | Long text |
| DATE / DATETIME | Dates and times |
| BOOLEAN | True / false |
Related tools & charts