Category: Conditionals

COALESCE

COALESCE returns the first value that is not NULL. If all values are NULL the result is NULL.

Syntax

COALESCE(expression [, expression]*)

AMC specifics

  • All expressions must have the same type. IFNULL and NVL are aliases of COALESCE.
  • COALESCE helps with GREATEST and LEAST, where a single NULL turns the whole result into NULL.

Example

Report missing campaign names as their own "unknown" row.

SELECT
  COALESCE(campaign, 'unknown') AS campaign_name,
  SUM(impressions) AS impressions
FROM
  sponsored_ads_traffic
GROUP BY
  1

Checked against the AMC schema, not executed on an AMC instance.

Related functions: NULLIF

Source: advertising.amazon.com (retrieved 2026-10-09)