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 values across several rows
SQLite: Use SUM to calculate a total quantity.
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
Count the rows in a table
SQLite: COUNT(*) includes every row, including rows with NULL columns.
SQLite✓ Tested
Create a table and insert its first row
SQLite: Define column types and a primary key, then insert one row using an explicit column list.
SQLite✓ Tested
Delete one row from a practice table
SQLite: Restrict DELETE with a primary-key condition and verify the remaining row count.
SQLite✓ Tested
Display a fallback for missing data
SQLite: Return a supplied label when a column contains NULL.
SQLite✓ Tested
Filter by a numeric comparison
SQLite: Keep rows whose quantity exceeds a chosen threshold.
SQLite✓ Tested
Filter groups after aggregation
SQLite: Use HAVING to test a group’s calculated total.
SQLite✓ Tested
Find missing values with IS NULL
SQLite: Use IS NULL rather than equality to test for missing data.
SQLite✓ Tested
Give a result column a readable name
SQLite: Use AS to label a computed result column.
SQLite✓ Tested