The snippet library.
Small, practical examples. Search by task or narrow things down below.
Search for a literal LIKE wildcard
SQLite: Declare an escape character so a percent sign in the pattern is literal.
SQLite✓ Tested
Select the top row in each group with a tie-breaker
SQLite: Filter an outer query on ROW_NUMBER because window functions are not evaluated in WHERE.
SQLite✓ Tested
Select values in an inclusive range
SQLite: BETWEEN includes both endpoints of the range.
SQLite✓ Tested
Set a JSON property
Create an updated JSON document from existing text.
json_set✓ Tested
Show a group total beside each detail row
SQLite: A partitioned aggregate preserves detail rows instead of collapsing them with GROUP BY.
SQLite✓ Tested
Sort preferred rows ahead of other rows
SQLite: A CASE ordering key expresses business priority before a stable secondary sort.
SQLite✓ Tested
Sort the highest quantities first
SQLite: Specify descending order and a stable tie breaker.
SQLite✓ Tested
Sum a row and its immediate predecessor
SQLite: A ROWS frame counts physical ordered rows rather than all peers with the same sort value.
SQLite✓ Tested
Treat an empty trimmed value as missing
SQLite: NULLIF converts an empty string to NULL before a fallback is applied.
SQLite✓ Tested
Turn a condition into a result label
SQLite: Use CASE to describe stock availability for each row.
SQLite✓ Tested
Turn known group values into columns
SQLite: Conditional aggregation gives a portable pivot when the category set is known.
SQLite✓ Tested
Undo a multi-row transfer atomically
SQLite: The first transaction commits the fixtures. Rolling back the second transaction restores both sides of the attempted transfer.
SQLite✓ Tested