Rank archive
Guides grouped by the expected difficulty and amount of SQL context they assume.
Calculate a future or past date by adding or subtracting an interval from an existing date.
Use `EXISTS` when you only need to test whether a related row exists, not return one output row per match.
`UNION` removes duplicates, while `UNION ALL` keeps them. Picking the wrong one silently changes row counts.
Merge result sets from two `SELECT` statements into one, removing duplicate rows by default.
Append result sets together without removing duplicates.
Save a `SELECT` statement as a named view so it can be queried like a table.
Return only part of a text value by position and length.
Return the year component from a date or timestamp value.
Return all rows from the left table and matching rows from the right, filling NULL where no match exists.
Use `HAVING` to filter aggregate results after `GROUP BY`, the same way `WHERE` filters individual rows before grouping.
Put right-table filters in the `ON` clause when you want to keep unmatched left-side rows.
Group rows by the candidate key and keep only values that appear more than once.
Return only the rows that appear in both result sets using `INTERSECT`.
Return rows from the first query that do not appear in the second query using `EXCEPT`.
Use a `LEFT JOIN` and filter for `NULL` on the joined table to find missing relationships.
Convert a numeric value into a formatted string with a fixed number of decimal places, optionally including thousands separators.
Aggregate rows by category with `GROUP BY` and count how many rows fall into each group.
Bucket dates into month starts, then aggregate counts or totals per month.
Use more than one column in `GROUP BY` when each combination defines a separate aggregate bucket.
Use `BEGIN`, `COMMIT`, and `ROLLBACK` to execute multiple statements as an atomic unit.
Combine rows from two tables when matching keys exist in both tables.
Use `WITH` to define a named temporary result set that can be referenced in the main query, improving readability over inline subqueries.
Embed a `SELECT` inside another query to filter, compute, or supply values that depend on aggregated or derived data.
Skip earlier rows and return the next slice of a sorted result set.
Convert a text string in a known format into a native DATE value using engine-specific parsing functions.
Evaluate conditions row-by-row inside a `SELECT` to produce computed columns based on branching logic.
Use `NULLIF` to convert a specific value to `NULL`, most commonly to prevent division-by-zero errors.
Filter `NULL` values out of the right side before using `NOT IN`, or the predicate can exclude everything.
`WHERE` filters individual rows before grouping. `HAVING` filters grouped results after aggregates are computed.