Join on single key with RELATED()

The RELATED() function family provides a concise way to join and group by features across entities using:

  • one foreign key ↔ one primary key (equivalent to a join)
  • one primary key ↔ multiple foreign keys with aggregation (equivalent to a group by)
  • one foreign key ↔ multiple foreign keys with aggregation (equivalent to a join + group by)

These functions are syntactic sugar that simplifies common patterns that would otherwise require the more verbose EXTEND() operation.

Syntax


-- foreign key ↔ primary key
RELATED(<feature> VIA <foreign_key>)

-- one primary key ↔ multiple foreign keys with aggregation
RELATED_<AGG>(<expression> BY <foreign_key> VIA <primary_key>)

-- one foreign key ↔ multiple foreign keys with aggregation
RELATED_<AGG>(<expression> BY <foreign_key> VIA <foreign_key>)
sql

Example

Interactive examples

The examples on this page use data and features from the Datasets page, which will be created automatically if needed.

Primary key ↔ primary key

Features depending on the same input are linked automatically. No need to use RELATED() in this case.

Foreign key ↔ primary key

Primary key ↔ foreign keys

Foreign key ↔ foreign keys

Self-join with aggregation

Relationship to EXTEND

The RELATED() functions are syntactic sugar for the more general EXTEND() operation.

If you need more complex binding logic, multiple fields at once, or work with arrays of rows, see the EXTEND documentation which includes the equivalence between RELATED() and EXTEND().

Last update at: 2025/12/05 16:03:14
Last updated: 2025-12-05 16:07:55