surfacerankingbest
Rankingaggregate · returns varchar

BEST

Pick the single best value from a group by a plain-English quality criterion

Per-group — reads the whole group in one call.

rankingllmtext

Syntax

BEST({{ values }})
BEST({{ values }}, '{{ criteria }}')

Arguments

nametypedescription
valuesVARCHARValues to choose from
criteria(optional)VARCHARSelection criteria: 'most complete', 'most recent', 'shortest', etc.

About

Pick the single best value from a group of candidates, using a plain- English quality criterion. Returns one value (not a merged record), so it's appropriate when you already have multiple candidates for the same thing and just want the strongest one. Useful for picking a canonical row from near-duplicates — the "best" customer-support response from multiple agent replies, the most authoritative-looking version of a product title across vendors, the clearest of several paraphrased sentences. Pass an optional criterion string (`'highest quality'`, `'most specific'`, `'most recent wording'`, `'most actionable'`); default is highest overall quality. Close relatives in the same family: BEST — pick one value from a group (this one) GOLDEN_RECORD — merge multiple records into a composite COALESCE_SMART — pick the best non-null scalar value

Examples

Selects best quality email from group

WITH
  test_data AS (
    SELECT
      *
    FROM
      (
        VALUES
          ('john@gmail.com'),
          ('JOHN@GMAIL.COM'),
          ('j@gmail.com'),
          (NULL)
      ) AS t (email)
  )
SELECT
  BEST (email, 'highest quality')
FROM
  test_data

Nearby rabbit holes

same domain
Climb back to The Looking Glass