SQL Cheatsheet
Searchable SQL command reference with syntax and examples.
Loading tool...
Related Tools
About this tool
Searchable SQL command reference with syntax and examples.
Searchable SQL command reference with syntax and examples.
Searchable SQL command reference with syntax and examples.
SELECT * FROM tableAll columnsSELECT col1, col2 FROM tableSpecific columnsSELECT DISTINCT col FROM tableUnique valuesSELECT col AS alias FROM tableColumn aliasSELECT COUNT(*) FROM tableCount rowsSELECT AVG(col) FROM tableAverageSELECT SUM(col) FROM tableSumSELECT MAX(col), MIN(col) FROM tableMax and MinWHERE col = 'value'EqualityWHERE col != 'value'InequalityWHERE col IN (1, 2, 3)In listWHERE col BETWEEN 10 AND 20RangeWHERE col LIKE '%text%'Pattern matchWHERE col IS NULLNull checkORDER BY col ASCAscendingORDER BY col DESCDescendingLIMIT 10 OFFSET 20PaginationINNER JOIN t2 ON t1.id = t2.idMatching rowsLEFT JOIN t2 ON t1.id = t2.idAll left + matching rightRIGHT JOIN t2 ON t1.id = t2.idAll right + matching leftFULL OUTER JOIN t2 ON t1.id = t2.idAll rows both tablesCROSS JOIN t2Cartesian productGROUP BY colGroup rowsGROUP BY col HAVING COUNT(*) > 1Filter groupsGROUP BY col1, col2Multiple columnsINSERT INTO t (col) VALUES ('val')Insert rowUPDATE t SET col='val' WHERE id=1Update rowsDELETE FROM t WHERE id=1Delete rowsTRUNCATE TABLE tDelete all rowsUPSERT / INSERT ... ON CONFLICTUpsertCREATE TABLE t (id INT PRIMARY KEY, name TEXT)Create tableALTER TABLE t ADD COLUMN email TEXTAdd columnDROP TABLE tDrop tableCREATE INDEX idx ON t(col)Create indexCREATE VIEW v AS SELECT ...Create view