The snippet library.
Small, practical examples. Search by task or narrow things down below.
Repeat the first ordered value beside each row
SQL: FIRST_VALUE reads the first value in the current window frame.
SQL✓ Tested
Replace a literal substring
SQL: REPLACE performs a literal replacement rather than a regular-expression substitution.
SQL✓ Tested
Replace NULL in a result
Choose a fallback for a missing value.
COALESCE✓ Tested
Report duplicate business values and their frequency
SQL: Group by a candidate business key and retain only groups with multiple rows.
SQL✓ Tested
Require a value with NOT NULL
SQL: Declare required fields at the database boundary, not only in application validation.
SQL✓ Tested
Require two filtering conditions
SQL: Combine category and quantity conditions with AND.
SQL✓ Tested
Return all rows tied for the maximum in a group
SQL: An equality comparison with a grouped maximum retains ties rather than choosing one arbitrary row.
SQL✓ Tested
Return zero for a sum over no rows
SQL: SUM produces NULL for an empty input; COALESCE supplies the desired reporting default.
SQL✓ Tested
Run a first SELECT query
SQL: Return a literal value without creating a table.
SQL✓ Tested
Search for a literal LIKE wildcard
SQL: Declare an escape character so a percent sign in the pattern is literal.
SQL✓ Tested
Select an inclusive range
Find rows with values between two endpoints.
BETWEEN✓ Tested
Select specific columns
Read only the fields a result needs.
SELECT✓ Tested