The snippet library.
Small, practical examples. Search by task or narrow things down below.
Join related rows from two tables
SQL: Match a category key to its display label with an explicit join condition.
SQL✓ Tested
Keep rows matching a condition
SQL: Use WHERE to select rows with a particular category.
SQL✓ Tested
Match a text prefix
SQL: Use a percent wildcard after a known prefix.
SQL✓ Tested
Match one value from a short list
SQL: Use IN for a set of allowed values.
SQL✓ Tested
Read named columns from a table
SQL: Choose the columns needed and request a deterministic row order.
SQL✓ Tested
Read the smallest and largest values
SQL: Use MIN and MAX without sorting and fetching every row.
SQL✓ Tested
Remove duplicate result values
SQL: Use DISTINCT when repeated category values are not useful.
SQL✓ Tested
Require two filtering conditions
SQL: Combine category and quantity conditions with AND.
SQL✓ Tested
Run a first SELECT query
SQL: Return a literal value without creating a table.
SQL✓ Tested
Select values in an inclusive range
SQL: BETWEEN includes both endpoints of the range.
SQL✓ Tested
Sort the highest quantities first
SQL: Specify descending order and a stable tie breaker.
SQL✓ Tested
Turn a condition into a result label
SQL: Use CASE to describe stock availability for each row.
SQL✓ Tested