FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
SQLiteGetting Started

Accept either of two conditions

SQLite: Use OR to keep matching names or out-of-stock rows.

SQLite✓ Tested
SQLiteSchema design & transactions

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
SQLiteDates & time

Add days to a date

Use a date modifier for calendar arithmetic.

date✓ Tested
SQLiteGetting Started

Add values across several rows

SQLite: Use SUM to calculate a total quantity.

SQLite✓ Tested
SQLiteConstraints & defaults

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
SQLiteSubqueries & ranked selection

Attach an overall count to every row

SQLite: An uncorrelated scalar subquery supplies the same aggregate to each output row.

SQLite✓ Tested
SQLiteConstraints & defaults

Block deletion of a referenced parent

SQLite: The default foreign-key action prevents deletion while a child still refers to the parent.

SQLite✓ Tested
SQLiteJSON data

Build a JSON array from rows

Aggregate ordered text values into JSON.

json_group_array✓ Tested
SQLiteSubqueries & ranked selection

Build a query from several named stages

SQLite: Separate row selection from aggregation using two common table expressions.

SQLite✓ Tested
SQLiteWindow analytics

Calculate a cumulative integer percentage

SQLite: Divide a running window sum by the complete total using a unique ordering key.

SQLite✓ Tested
SQLiteGetting Started

Calculate a total for each group

SQLite: Group nonmissing categories and calculate separate totals.

SQLite✓ Tested
SQLiteGetting Started

Calculate a value with SELECT

SQLite: Evaluate a small arithmetic expression on the database server.

SQLite✓ Tested