Converter Web ToolsConverter WebTools

SQL Cheat Sheet — Commands & Syntax

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

StatementWhat it does
SELECT * FROM tableSelect all columns
SELECT col1, col2 FROM tableSelect specific columns
WHERE price > 100Filter rows
ORDER BY col DESCSort results
LIMIT 10Limit number of rows
SELECT DISTINCT colUnique values
WHERE name LIKE 'A%'Pattern match

Joins & grouping

StatementWhat it does
INNER JOIN b ON a.id=b.aidRows matching in both tables
LEFT JOIN b ON ...All left rows + matches
GROUP BY colGroup rows
HAVING COUNT(*) > 1Filter groups
COUNT() / SUM() / AVG()Aggregate functions

Modifying data

StatementWhat it does
INSERT INTO t (a) VALUES (1)Add a row
UPDATE t SET a=1 WHERE id=2Change rows
DELETE FROM t WHERE id=2Remove rows
CREATE TABLE t (...)Create a table
ALTER TABLE t ADD colModify a table
DROP TABLE tDelete a table

Common data types

TypeUse
INTWhole numbers
DECIMAL(10,2)Exact decimals (money)
VARCHAR(255)Short text
TEXTLong text
DATE / DATETIMEDates and times
BOOLEANTrue / false

Related tools & charts