The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept either of two conditions
SQLite: Use OR to keep matching names or out-of-stock rows.
SQLite✓ Tested
Add an optional field to an existing table
SQLite: A nullable column permits existing rows to remain valid while data is filled later.
SQLite✓ Tested
Add days to a date
Use a date modifier for calendar arithmetic.
date✓ Tested
Add values across several rows
SQLite: Use SUM to calculate a total quantity.
SQLite✓ Tested
Apply a default when an insert omits a column
SQLite: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.
SQLite✓ Tested
Attach an overall count to every row
SQLite: An uncorrelated scalar subquery supplies the same aggregate to each output row.
SQLite✓ Tested
Block deletion of a referenced parent
SQLite: The default foreign-key action prevents deletion while a child still refers to the parent.
SQLite✓ Tested
Build a JSON array from rows
Aggregate ordered text values into JSON.
json_group_array✓ Tested
Build a query from several named stages
SQLite: Separate row selection from aggregation using two common table expressions.
SQLite✓ Tested
Calculate a cumulative integer percentage
SQLite: Divide a running window sum by the complete total using a unique ordering key.
SQLite✓ Tested
Calculate a total for each group
SQLite: Group nonmissing categories and calculate separate totals.
SQLite✓ Tested
Calculate a value with SELECT
SQLite: Evaluate a small arithmetic expression on the database server.
SQLite✓ Tested