Cheat Sheets

SQL Cheat Sheet (2026): SELECT, WHERE, JOIN, GROUP BY & Indexes

By ArpaNeuro Team September 25, 2026
SQL cheat sheet MySQL

A SQL cheat sheet is the language of relational databases: SELECT columns from tables, filter with WHERE, combine with JOIN, aggregate with GROUP BY, and write with INSERT/UPDATE/DELETE. Indexes speed lookups at the cost of writes. The ideas transfer across MySQL, PostgreSQL, and SQL Server; dialects differ on functions and types.

This SQL cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • SELECT: SELECT id, email FROM users — list columns, avoid SELECT * in app code.
  • WHERE: Filter rows. AND/OR, IN, BETWEEN, LIKE, IS NULL.
  • ORDER / LIMIT: ORDER BY created_at DESC LIMIT 20 OFFSET 0.
  • JOIN: INNER JOIN matches both sides. LEFT JOIN keeps the left table.
  • GROUP BY: Aggregates (COUNT, SUM) per group. HAVING filters groups.
  • INSERT: INSERT INTO t (a, b) VALUES (1, "x").
  • UPDATE/DELETE: Always WHERE. Start with a SELECT of the same predicate.
  • Index: INDEX (email) for lookups and joins. Prefix LIKE "ab%" can use an index; %ab cannot.

Copy-paste examples

Filter, join, and aggregate

Qualify column names when two tables share id. Aliases keep the query readable.

SELECT p.id, p.title, COUNT(c.id) AS comment_count
FROM posts AS p
LEFT JOIN comments AS c ON c.post_id = p.id
WHERE p.published = 1
GROUP BY p.id, p.title
ORDER BY p.id DESC
LIMIT 20;

Common mistakes

  • DELETE FROM users without WHERE (or with a buggy predicate) in production.
  • SELECT * in hot API paths and shipping extra blobs over the wire.
  • Filtering in PHP after fetching the whole table.
  • Indexing every column “just in case” and slowing writes.

FAQ

  1. Is SQL a programming language? It is a query language for sets of rows. You still use PHP/Python/etc. for application logic. Many job posts still say “SQL programming.”
  1. MySQL vs SQL? SQL is the language. MySQL is a database product that implements a dialect of SQL.
  1. How do I prevent SQL injection? Parameterized queries (PDO, prepared statements). Never concatenate user input into SQL strings.

Related SQL cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →