Cheatsheet SQL
Riferimento rapido per sintassi SQL, join, funzioni e tipi di dati.
Come funziona
SQL evaluates logically as FROM/JOIN -> WHERE -> GROUP BY -> HAVING -> SELECT/WINDOW -> DISTINCT -> ORDER BY -> LIMIT, even though `SELECT` is written first.
Kit di sopravvivenza
I pochi comandi da imparare per primi.
42 comandi
Select, Filter & Pagination
Filter predicates safely, avoid NULL traps, sort, and paginate efficiently.
- Essenziale
Filter rows, sort deterministically, and cap returned rows
SELECT <cols> FROM <table> WHERE <cond> ORDER BY <col> DESC LIMIT <n>;Componi il comando
SELECT <cols> FROM <table> WHERE <cond> ORDER BY <col> DESC LIMIT <n>;I valori vengono inseriti esattamente come li digiti. Racchiudili tra virgolette se contengono spazi o caratteri speciali.
Quando usarlo
Adding a tie-breaker column to `ORDER BY` guarantees repeatable pagination order.
Esempio
SELECT id, email, created_at FROM users WHERE status = 'active' ORDER BY created_at DESC, id DESC LIMIT 25;
Joins & Set Operations
Combine related tables cleanly and find orphan or unmatched rows.
Aggregation, CTEs & Window Functions
Group metrics, stage readable queries with CTEs, and rank without collapsing rows.
Insert, Upsert, Update & Delete
Write idempotent mutations safely inside transactions without locking accidents.
Schema, Constraints, JSON & Performance
Design tables, composite indexes, JSON queries, and inspect EXPLAIN plans.