SQL Syntax Cheatsheet

Search SQL keywords, clauses and functions with syntax and dialect notes.

A searchable SQL reference covering ANSI syntax plus MySQL, PostgreSQL, SQLite and SQL Server variations, with the syntax pattern, a description and dialect notes for queries, joins, DML, DDL and window functions.

What is the difference between WHERE and HAVING?

WHERE filters individual rows before grouping, while HAVING filters groups after aggregation. You use HAVING to keep, for example, only the groups whose COUNT(*) is greater than five, which WHERE cannot do because the aggregate is not yet computed.

This is a searchable SQL syntax cheatsheet covering the keywords, clauses and functions you use every day. Each entry gives the syntax pattern, a one-line description, and — where the dialects diverge — notes for MySQL, PostgreSQL, SQLite and SQL Server, so you can write portable queries or adapt one to a specific engine.

How it works

SQL is largely standardised by ANSI, but every database adds its own spellings for common tasks. The reference is grouped so you can browse by area: Query (SELECT, DISTINCT, CTEs), Clause (WHERE, GROUP BY, HAVING, ORDER BY, LIMIT), Join types, DML (INSERT, UPDATE, DELETE, upsert), DDL (CREATE, ALTER, DROP, indexes), aggregate and scalar functions, window functions and transactions. Search matches the keyword, the syntax and the dialect notes, so a query for “pagination” or “auto increment” surfaces the right entries even if you do not remember the exact keyword.

Tips and gotchas

The single most useful thing to internalise is the logical execution order of a SELECT: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. It explains why you cannot reference a SELECT alias inside WHERE, and why aggregate filters belong in HAVING. Watch the dialect notes for the big traps: FULL OUTER JOIN is missing in MySQL and SQLite, auto-increment is spelled four different ways, and upsert syntax differs by engine. Everything runs in your browser; this tool never connects to a database or uploads your input.