Cheat sheets / SQL
SQL Cheat Sheet
36 queries and clauses written as working examples on a users and an orders table. Click one to copy it, then change the names to match your tables.
This page also works as a hotkey overlay. Hold Ctrl+Space to see it, let go to hide it. What is this?
Query rows
Filter rows
These go after FROM. NULL is never equal to anything, so test it with IS NULL, not = NULL.
Join tables
The join examples assume FROM orders o in front of them.
Group and summarize
Change data
An UPDATE or DELETE without WHERE changes every row in the table. Run it inside BEGIN, check the result, then COMMIT or ROLLBACK.
Tables
No examples match .
This is standard SQL that runs on PostgreSQL, MySQL and SQLite. On SQL Server, write SELECT TOP 10 instead of LIMIT 10 and BEGIN TRANSACTION instead of BEGIN.
Keep this cheat sheet on a hotkey
BrainRAM is a small free app for Windows. Hold Ctrl+Space and this page appears on top of whatever you are doing. Let go and it's gone. Click a cell and it's copied.
Each row is one topic, named at its left edge, in the same order as this page. So tables is always the bottom row, and after a few days you stop reading and just reach for the spot.
- Download BrainRAM Free, no account, works offline. The installer isn't code-signed yet, so Windows shows a blue warning: click More info, then Run anyway.
- Add this page to BrainRAM Opens BrainRAM with this page ready to import.
BrainRAM runs on Windows today. The macOS and Linux versions are on the way.
Email me when mine is ready