SQL functions

Practical SQL function reference pages for the most-used patterns.

Edit this pageReport an issue

Common building blocks

Every example in this section runs against a seeded database — edit and execute it inline.Open the playground →

Why these matter

Most business logic fails not because of a complex algorithm, but because the team did not agree on:

  • what counts as a row
  • how NULL values are treated
  • how ties are ordered
  • whether a window function or aggregate is the right tool

Good habits

  • prefer explicit ORDER BY in window functions
  • use PARTITION BY for per-group ranking
  • guard nullable results with COALESCE or CASE
  • document tie policy when ranking and paging
  • add a stable tiebreaker before shipping user-facing ranking logic
Was this page helpful?

On this page