FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
SQLiteRelationships & missing data

Find parents whose every child meets a rule

SQLite: Combine existence with the absence of a violating child to exclude parents with no children.

SQLite✓ Tested
SQLiteRelationships & missing data

Find parents with at least two child rows

SQLite: Use a correlated count when testing a per-parent threshold.

SQLite✓ Tested
SQLiteRelationships & missing data

Find records without any related rows

SQLite: NOT EXISTS avoids the NULL pitfalls of NOT IN when the subquery column can be missing.

SQLite✓ Tested
SQLiteBulk changes & set operations

Find rows in the first result but not the second

SQLite: EXCEPT calculates a distinct result-set difference.

SQLite✓ Tested
SQLiteBulk changes & set operations

Find rows shared by two query results

SQLite: INTERSECT compares complete selected rows and removes duplicates.

SQLite✓ Tested
SQLiteDates & time

Find the first day of a month

Round a date to its calendar month boundary.

date✓ Tested
SQLiteSubqueries & ranked selection

Find the second-highest distinct value

SQLite: Select the maximum below the overall maximum to skip ties at the top.

SQLite✓ Tested
SQLiteDates & time

Format a timestamp

Extract a year and month from ISO timestamp text.

strftime✓ Tested
SQLiteRelationships & missing data

Generate every combination of two sets

SQLite: CROSS JOIN creates one result per possible pair, so the output size is the product of the input sizes.

SQLite✓ Tested
SQLiteQueries & text

Generate numbers with a recursive CTE

Build a bounded sequence using SQL recursion.

recursive CTE✓ Tested
SQLiteGetting Started

Give a result column a readable name

SQLite: Use AS to label a computed result column.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Group by more than one field

SQLite: Each distinct combination of grouping fields produces its own row.

SQLite✓ Tested