SQL Cheat Sheet

Last Updated: November 21, 2025

SELECT Queries

SELECT * FROM table
Select all columns from table
SELECT column1, column2 FROM table
Select specific columns
SELECT DISTINCT column FROM table
Select unique values
SELECT * FROM table WHERE condition
Filter rows with WHERE
SELECT * FROM table ORDER BY column ASC/DESC
Sort results
SELECT * FROM table LIMIT 10
Limit number of results

Filtering & Conditions

WHERE age > 18
Greater than comparison
WHERE name = 'John'
Equality comparison
WHERE age BETWEEN 18 AND 65
Range condition
WHERE name LIKE '%John%'
Pattern matching
WHERE city IN ('NYC', 'LA')
Multiple values
WHERE age IS NULL
Check for NULL values

Joins

INNER JOIN table2 ON table1.id = table2.id
Return matching rows from both tables
LEFT JOIN table2 ON table1.id = table2.id
All rows from left table
RIGHT JOIN table2 ON table1.id = table2.id
All rows from right table
FULL OUTER JOIN table2 ON table1.id = table2.id
All rows from both tables

Aggregate Functions

COUNT(*)
Count rows
SUM(column)
Sum of values
AVG(column)
Average of values
MAX(column)
Maximum value
MIN(column)
Minimum value
GROUP BY column
Group rows by column
HAVING condition
Filter groups

Data Modification

INSERT INTO table (col1, col2) VALUES (val1, val2)
Insert new row
UPDATE table SET col1 = val1 WHERE condition
Update rows
DELETE FROM table WHERE condition
Delete rows

Table Operations

CREATE TABLE table (id INT PRIMARY KEY, name VARCHAR(100))
Create new table
ALTER TABLE table ADD COLUMN col TYPE
Add column to table
DROP TABLE table
Delete table
💡 Pro Tip: Always use WHERE clause with UPDATE and DELETE to avoid modifying all rows!
← Back to Databases & APIs | Browse all categories | View all cheat sheets