FIND YOUR NEXT FEW LINES

Results for “SQL”

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

500 snippets foundClear filters
PostgresRelationships & missing data

Find records without any related rows

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

Postgres✓ Tested
PostgresBulk changes & set operations

Find rows in the first result but not the second

Postgres: EXCEPT calculates a distinct result-set difference.

Postgres✓ Tested
PostgresBulk changes & set operations

Find rows shared by two query results

Postgres: INTERSECT compares complete selected rows and removes duplicates.

Postgres✓ Tested
SQLJoins & subqueries

Find rows with a related record

Use EXISTS without duplicating the outer rows.

EXISTS✓ Tested
SQL ServerDates & text

Find the final day of a month

Use EOMONTH without manually calculating month length.

EOMONTH✓ Tested
SQLiteDates & time

Find the first day of a month

Round a date to its calendar month boundary.

date✓ Tested
PostgresSubqueries & ranked selection

Find the second-highest distinct value

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

Postgres✓ Tested
SQLiteDates & time

Format a timestamp

Extract a year and month from ISO timestamp text.

strftime✓ Tested
PostgresDates & series

Format a timestamp with to_char

Produce a fixed numeric date string.

to_char✓ Tested
SQL ServerTransactions & tables

Generate a bounded sequence recursively

Use a recursive CTE with a recursion limit.

recursive CTE✓ Tested
PostgresDates & series

Generate a sequence of numbers

Create rows without a stored table.

generate_series✓ Tested
PostgresRelationships & missing data

Generate every combination of two sets

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

Postgres✓ Tested