The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept either of two conditions
SQL: Use OR to keep matching names or out-of-stock rows.
SQL✓ Tested
Add values across several rows
SQL: Use SUM to calculate a total quantity.
SQL✓ Tested
Calculate a total for each group
SQL: Group nonmissing categories and calculate separate totals.
SQL✓ Tested
Calculate a value with SELECT
SQL: Evaluate a small arithmetic expression on the database server.
SQL✓ Tested
Count the rows in a table
SQL: COUNT(*) includes every row, including rows with NULL columns.
SQL✓ Tested
Create a table and insert its first row
SQL: Define column types and a primary key, then insert one row using an explicit column list.
SQL✓ Tested
Delete one row from a practice table
SQL: Restrict DELETE with a primary-key condition and verify the remaining row count.
SQL✓ Tested
Display a fallback for missing data
SQL: Return a supplied label when a column contains NULL.
SQL✓ Tested
Filter by a numeric comparison
SQL: Keep rows whose quantity exceeds a chosen threshold.
SQL✓ Tested
Filter groups after aggregation
SQL: Use HAVING to test a group’s calculated total.
SQL✓ Tested
Find missing values with IS NULL
SQL: Use IS NULL rather than equality to test for missing data.
SQL✓ Tested
Give a result column a readable name
SQL: Use AS to label a computed result column.
SQL✓ Tested