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