Cheat Sheets

SQL Interview Questions Cheat Sheet: Joins, Indexes, NULL & Aggregation

By ArpaNeuro Team September 26, 2026
SQL interview cheat sheet

SQL interviews ask you to write a join, explain why WHERE col = NULL is wrong, and say what an index is for. Be ready to aggregate with GROUP BY, to discuss N+1 queries from application code, and to sketch a primary key plus a unique email index. Whiteboard SQL beats buzzwords.

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

  • NULL: = NULL is unknown. Use IS NULL. NOT IN with NULL in the list is a famous trap.
  • INNER vs LEFT: INNER drops non-matches. LEFT keeps the left side.
  • PK / FK: Primary key uniquely identifies a row. Foreign key points at another table’s key.
  • Index: B-tree lookup for WHERE/JOIN/ORDER. Write cost. Composite leftmost prefix.
  • GROUP BY: Selected non-aggregated columns must be grouped (strict engines).
  • DISTINCT: Unique rows. Not a substitute for understanding why duplicates appeared.
  • Transaction: ACID in InnoDB. BEGIN/COMMIT. Isolation levels if they push.
  • N+1: Loop in PHP/Python running one query per row. Fix with JOIN or IN.

Copy-paste examples

Users with no orders (LEFT JOIN anti-pattern done right)

Anti-join: left join then WHERE right.id IS NULL. Interview classic.

SELECT u.id, u.email
FROM users AS u
LEFT JOIN orders AS o ON o.user_id = u.id
WHERE o.id IS NULL;

Common mistakes

  • WHERE email = NULL.
  • Selecting non-grouped columns in MySQL ONLY_FULL_GROUP_BY off and getting random values.
  • Saying indexes make everything faster, including writes and tiny tables.
  • Cannot write a three-table join for “posts with author name and comment count.”

FAQ

  1. What does EXPLAIN tell you? How the optimizer plans to read tables: type of access, possible keys, rows estimate. type=ALL is a full scan — often a missing index.
  1. VARCHAR vs TEXT? VARCHAR for short indexed strings (email). TEXT for long bodies; indexing rules differ by engine.
  1. DELETE vs TRUNCATE? DELETE is a DML row operation (can WHERE, can rollback in a transaction). TRUNCATE is DDL-ish, resets identity in MySQL, not for “delete this user.”

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 →