MySQL Joins, Subqueries, and CTEs Cheatsheet
inner joins, left joins, self joins, subqueries, derived tables, and common table expressions in MySQL.
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## joins
## subqueries and ctes
WITH recent_orders AS ( SELECT id, user_id, total_amount, created_at FROM orders WHERE created_at >= NOW() - INTERVAL 30 DAY ) SELECT user_id, COUNT(*) AS recent_order_count, SUM(total_amount) AS revenue FROM recent_orders GROUP BY user_id;
# Create a readable query pipeline with `WITH`.
More in MySQL
MySQL Procedures, Triggers, and Events Cheatsheet
stored procedures, stored functions, delimiters, call, triggers, and scheduled events in MySQL.
MySQL Functions, JSON, and Date Cheatsheet
now, date_add, date_sub, date_format, timestampdiff, json_extract, json_set, json_object, concat, coalesce, and case in MySQL.
MySQL Backup, Restore, Import, and Export Cheatsheet
mysqldump, mysql restore, load data infile, select into outfile, mysqlimport, and MySQL Shell dump/load workflows.
MySQL Users, Grants, and Privileges Cheatsheet
create users, alter passwords, grant privileges, show grants, revoke access, and manage MySQL accounts safely.
MySQL Transactions and Locking Cheatsheet
start transaction, commit, rollback, savepoints, select for update, isolation levels, and InnoDB lock troubleshooting.
MySQL Indexes, EXPLAIN, and Performance Cheatsheet
index design, show index, explain, explain analyze, analyze table, and practical performance tuning workflows in MySQL.