SQL is one of the most valuable skills in tech — but remembering every command and query syntax is tough, especially when you’re starting out. That’s exactly why a good SQL cheat sheet is so useful.
So I built this one to be complete. Below you’ll find every essential SQL command — from basic SELECT statements to JOINs, aggregate functions, and table creation — all organized in one place with clear examples. Furthermore, you can download the whole thing as a free PDF to keep beside you while you work.
Let’s dive in.
Download the SQL Cheat Sheet PDF (Free)
Want this entire SQL cheat sheet as a printable PDF? You can download it for free — no email, no signup, no cost. Keep it open while you write queries, print it, or save it to your phone. Then use the reference sections below to learn each command.
Basic SELECT Queries
First, the SELECT statement — the foundation of SQL. It retrieves data from a table.
-- Select all columns
SELECT * FROM students;
-- Select specific columns
SELECT name, age FROM students;
-- Select unique values
SELECT DISTINCT city FROM students;
-- Limit results
SELECT * FROM students LIMIT 10;
Filtering with WHERE
Next, the WHERE clause filters rows based on conditions.
SELECT * FROM students WHERE age > 18;
SELECT * FROM students WHERE city = 'Lahore';
SELECT * FROM students WHERE age BETWEEN 18 AND 25;
SELECT * FROM students WHERE city IN ('Lahore','Delhi');
SELECT * FROM students WHERE name LIKE 'A%'; -- starts with A
SELECT * FROM students WHERE age IS NOT NULL;
Sorting & Limiting
ORDER BY sorts your results, and LIMIT controls how many rows return.
SELECT * FROM students ORDER BY age ASC; -- ascending
SELECT * FROM students ORDER BY age DESC; -- descending
SELECT * FROM students ORDER BY city, age; -- multiple columns
SELECT * FROM students LIMIT 5 OFFSET 10; -- skip 10, take 5
Aggregate Functions
Aggregate functions perform calculations on multiple rows and return a single value.
SELECT COUNT(*) FROM students; -- count rows
SELECT SUM(marks) FROM students; -- total
SELECT AVG(marks) FROM students; -- average
SELECT MAX(marks) FROM students; -- highest
SELECT MIN(marks) FROM students; -- lowest
GROUP BY & HAVING
GROUP BY groups rows by a column, and HAVING filters those groups.
-- Count students per city
SELECT city, COUNT(*)
FROM students
GROUP BY city;
-- Only cities with more than 5 students
SELECT city, COUNT(*)
FROM students
GROUP BY city
HAVING COUNT(*) > 5;
JOINs (Combining Tables)
JOINs combine rows from two or more tables. This is the most important advanced SQL skill.
-- INNER JOIN (matching rows only)
SELECT s.name, c.title
FROM students s
INNER JOIN courses c ON s.course_id = c.id;
-- LEFT JOIN (all from left table)
SELECT s.name, c.title
FROM students s
LEFT JOIN courses c ON s.course_id = c.id;
-- RIGHT JOIN (all from right table)
SELECT s.name, c.title
FROM students s
RIGHT JOIN courses c ON s.course_id = c.id;

Inserting Data
The INSERT statement adds new rows to a table.
-- Insert one row
INSERT INTO students (name, age, city)
VALUES ('Ali', 20, 'Lahore');
-- Insert multiple rows
INSERT INTO students (name, age)
VALUES ('Sara', 19), ('Dev', 21);
Updating Data
The UPDATE statement modifies existing rows. Always use WHERE — or you’ll update every row!
UPDATE students
SET age = 21
WHERE name = 'Ali';
UPDATE students
SET city = 'Karachi', age = 22
WHERE id = 5;
Deleting Data
The DELETE statement removes rows. Again, always use WHERE to avoid deleting everything.
DELETE FROM students WHERE id = 5;
DELETE FROM students WHERE age < 18;
Creating & Modifying Tables
These commands define and change the structure of your database tables.
-- Create a table
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
city VARCHAR(50)
);
-- Add a column
ALTER TABLE students ADD email VARCHAR(100);
-- Delete a column
ALTER TABLE students DROP COLUMN email;
-- Delete entire table
DROP TABLE students;
Common SQL Data Types
| Data Type | Used For |
|---|---|
| INT | Whole numbers |
| VARCHAR(n) | Text up to n characters |
| TEXT | Long text |
| DATE | Dates (YYYY-MM-DD) |
| DECIMAL(p,s) | Decimal numbers |
| BOOLEAN | True/False values |
Useful SQL Keywords Quick Reference
| Keyword | What It Does |
|---|---|
| SELECT | Retrieve data |
| WHERE | Filter rows |
| ORDER BY | Sort results |
| GROUP BY | Group rows |
| JOIN | Combine tables |
| INSERT | Add data |
| UPDATE | Modify data |
| DELETE | Remove data |
| DISTINCT | Unique values only |
| LIKE | Pattern matching |
How to Use This SQL Cheat Sheet Effectively
A cheat sheet works best as a quick reference, not a replacement for practice. Therefore, keep it open while you write queries. When you forget the syntax for a JOIN or GROUP BY, glance at it instead of breaking your flow to search online. Over time, the syntax becomes second nature.
Moreover, retype each query into a real SQL environment like SQLite, MySQL, or an online editor such as DB Fiddle. Active practice builds memory far better than passive reading. For beginners, work through the sections in order — SELECT first, then filtering, then JOINs.
Final Thoughts
This SQL cheat sheet covers everything you need for everyday database work — from basic SELECT statements to JOINs, table creation, and data types. Bookmark this page, download the PDF, and keep it close while you learn.
Above all, remember that SQL is learned by doing. Write queries, build small databases, and refer back here whenever you need a quick reminder. With consistent practice and this reference at your side, you’ll be writing confident SQL in no time.
Found this SQL cheat sheet helpful? Is there a command you’d like me to add? Drop a comment below — I read and reply to every one
Frequently Asked Questions (FAQ)
A SQL cheat sheet is a quick reference guide that summarizes the most important SQL commands, queries, and syntax in one place. It helps beginners and experienced developers quickly recall how to write SELECT statements, JOINs, aggregate functions, and more without searching online repeatedly.
You can download the complete SQL cheat sheet PDF for free directly from this page — no signup or payment required. It includes all essential SQL commands organized by topic, making it perfect for printing or keeping on your phone while working with databases.
The most important SQL commands are SELECT (retrieve data), WHERE (filter), ORDER BY (sort), GROUP BY (group), JOIN (combine tables), INSERT (add data), UPDATE (modify), and DELETE (remove). Mastering these covers the vast majority of everyday database work.
SQL is considered one of the easier technical skills to learn because its syntax closely resembles plain English. Beginners can write basic queries within their first day. The main challenge is mastering JOINs and subqueries, but consistent practice makes these manageable too.
SQL is used by all major relational databases including MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server, and SQLite. While there are minor syntax differences between them, the core SQL commands in this cheat sheet work across all of them.
You can practice SQL for free using online tools like DB Fiddle and SQLite Online that run in your browser with no installation. For interview-style practice, HackerRank and LeetCode offer free SQL problem sets that test the commands in this cheat sheet.



