Show Menu
Cheatography

SQL Cheat Sheet (DRAFT) by

SQL Basics for Data Science

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Categories

DDL: Data Definition Language
DQL: Data Query Language
DML: Data Manipu­lation Language
DCL: Data Control Language
TCL: Transa­ction Control Language

Commands

DDL
CREATE | DROP | ALTER | TRUNCATE | RENAME | COMMENT
DQL
SELECT
DML
INSERT | UPDATE | DELETE | LOCK | CALL | EXPLAIN PLA
DCL
GRANT | REVOKE
TCL
COMMIT | ROLLBACK | SAVEPOINT | SET TRANSA­CTION
 

Joins

Set Operations

 

Execution Order

1. FROM, JOIN
2. WHERE
3. GROUP BY
4. AGGREGATE FUNCTIONS
5. HAVING
6. WINDOW FUNCTIONS
7. SELECT
8. DISTINCT
9. UNION/­INT­ERS­ECT­/EXCEPT
10. ORDER BY
11. OFFSET
12. LIMIT/­FET­CH/TOP
Window functions can be used in SELECT and ORDER BY, however they cant be put anywhere in the FROM, WHERE, GROUP BY, or HAVING clauses.

Operators

Arithmetic
+ - * / %
Bitwise
& | ^
Comparison
= < > <= >= !< !> <> !=
Compound
+= -= *= /= %= &= |= ^=
Logical
AND | OR | NOT | ANY | SME | ALL | BETWEEN| IN | EXISTS | LIKE | IS NULL | UNIQUE