The snippet library.
Small, practical examples. Search by task or narrow things down below.
Remove duplicate result values
SQLite: Use DISTINCT when repeated category values are not useful.
SQLite✓ Tested
Remove duplicate values while keeping the smallest key
SQLite: Identify retained keys in a grouped subquery before deleting other copies.
SQLite✓ Tested
Remove surrounding spaces from text
SQLite: TRIM removes leading and trailing space characters by default.
SQLite✓ Tested
Repeat the first ordered value beside each row
SQLite: FIRST_VALUE reads the first value in the current window frame.
SQLite✓ Tested
Replace a literal substring
SQLite: REPLACE performs a literal replacement rather than a regular-expression substitution.
SQLite✓ Tested
Report duplicate business values and their frequency
SQLite: Group by a candidate business key and retain only groups with multiple rows.
SQLite✓ Tested
Require a value with NOT NULL
SQLite: Declare required fields at the database boundary, not only in application validation.
SQLite✓ Tested
Require two filtering conditions
SQLite: Combine category and quantity conditions with AND.
SQLite✓ Tested
Return all rows tied for the maximum in a group
SQLite: An equality comparison with a grouped maximum retains ties rather than choosing one arbitrary row.
SQLite✓ Tested
Return zero for a sum over no rows
SQLite: SUM produces NULL for an empty input; COALESCE supplies the desired reporting default.
SQLite✓ Tested
Run a first SELECT query
SQLite: Return a literal value without creating a table.
SQLite✓ Tested
Search a small FTS5 table
Use SQLite’s full-text index to match a term.
FTS5✓ Tested