`DELETE` is logged per-row and respects triggers; `TRUNCATE` deallocates whole pages and resets the table to empty. `TRUNCATE` is much faster on large tables but has caveats (no WHERE, can't be rolled back in some DBs).
Delete rows from one table conditional on a related table. PostgreSQL uses `USING`; MySQL uses join syntax in the DELETE. Run as a SELECT first to verify what you're about to remove.
`LIKE` uses `%` (any string) and `_` (single char). PostgreSQL `ILIKE` is case-insensitive. For real regex, reach for `SIMILAR TO` (POSIX) or `~` (PostgreSQL).
`FULL OUTER` keeps unmatched rows from BOTH sides. `CROSS JOIN` is the Cartesian product — every row of A paired with every row of B. Rare but useful for date-spine and matrix generation.
Returns every row from the LEFT side, NULL-filled where the right side doesn't match. The standard pattern for "this entity and its optional children".
Name a subquery so you can refer to it like a table. Improves readability for complex multi-stage queries — and lets you reuse the same logical block multiple times.
`LIMIT N OFFSET M` is universal — but degrades on deep pages (the DB still has to scan past M rows). Keyset (cursor) pagination is much faster for huge tables.
Native array columns avoid an extra join for "small list of things per row" patterns — tags, categories, allowed_roles. Combine with GIN index for fast `@>` / `&&` operators.
`EXTRACT(field FROM timestamp)` pulls year, month, hour, day-of-week, week, epoch — whatever you need to group, filter, or render. Standard SQL across every database.
Generate a row per day (or month, year, hour) without a calendar table. Useful for filling gaps when a date has no events but you still want it in your output.
`WITH RECURSIVE` lets a CTE refer to itself. The standard way to walk parent/child trees (org charts, comment threads, category nestings) in a single query.
A self-join is just a regular join with the same table aliased twice. The canonical example is an employee table where each row points to a manager in the same table.
SQL date_trunc — Bucket Times into Hours/Days/Weeks
`date_trunc('day', ts)` rounds a timestamp down to the start of the day. Use for time-series GROUP BYs — daily/weekly/hourly buckets without messy arithmetic.