Looker Explore joins: define relationships and validate fanout-prone measures
In a Looker Explore, `sql_on` alone is not enough to model a join safely. Declare the relationship from the base Explore view to the joined view, and mark each view’s genuinely unique key with `primary_key: yes`. This lets Looker handle measures correctly when a one-to-many join repeats fact rows. Symmetric aggregates still depend on database-dialect support and correct model metadata, so verify the results.
Looker Explore joins: define relationships and validate fanout-prone measures
In a Looker Explore, sql_on alone is not enough to model a join safely. Declare the relationship from the base Explore view to the joined view, and mark each view’s genuinely unique key with primary_key: yes. This lets Looker handle measures correctly when a one-to-many join repeats fact rows. Symmetric aggregates still depend on database-dialect support and correct model metadata, so verify the results.
What an Explore join defines
In a LookML model file, explore sets the base view and each join defines how another view connects. Looker includes joins needed by the selected fields. The main parameters are sql_on (the SQL ON condition), type (left_outer, inner, full_outer, or cross; default left_outer), relationship (one_to_one, many_to_one, one_to_many, or many_to_many), and each view’s primary_key: yes declaration. Relationship is from the base Explore to the joined view. Looker defaults an omitted relationship to many_to_one, so state the actual cardinality explicitly.
Example: why an order total can double
This is invented teaching data, not a real result. Order 1 has a total of 100 and two item rows worth 40 and 60. A plain SQL join repeats the order row for each item:
| order_id | order total | item_id | item amount |
|---|---|---|---|
| 1 | 100 | 501 | 40 |
| 1 | 100 | 502 | 60 |
Summing the repeated order total naively gives 200, while item amounts sum to 100. This is fanout: one row on one side matches multiple rows on the other. Looker’s symmetric aggregates can keep the order measure from being counted repeatedly, provided the primary keys and relationship are correct and the database dialect supports the feature. It is not a substitute for correct modeling. When unavailable or misconfigured, Looker may block a measure or omit it from the Explore rather than produce a usable result.
Declare keys and cardinality
With orders as the base Explore and multiple order_items per order, the relationship is one_to_many. Adapt this illustrative LookML to the real schema and SQL dialect:
view: orders {
dimension: id {
primary_key: yes
sql: ${TABLE}.id ;;
}
measure: total_revenue {
type: sum
sql: ${TABLE}.total ;;
}
}
view: order_items {
dimension: id {
primary_key: yes
sql: ${TABLE}.id ;;
}
dimension: order_id {
sql: ${TABLE}.order_id ;;
}
measure: item_revenue {
type: sum
sql: ${TABLE}.amount ;;
}
}
explore: orders {
join: order_items {
type: left_outer
relationship: one_to_many
sql_on: ${orders.id} = ${order_items.order_id} ;;
}
}Both orders.id and order_items.id must actually be unique and non-null within their views. If uniqueness requires multiple fields, define a genuine compound key; do not label a non-unique field as a primary key. Looker documentation requires valid primary keys on involved views for symmetric-aggregate behavior with sums and averages.
Validate the join
Check the grain of each source table and count duplicate or null key values.
Set relationship direction from the base Explore: orders to items is usually `one_to_many`; items to orders is usually `many_to_one`. Confirm the data supports that assumption.
Validate the LookML in Development Mode and open the Explore. Visible fields alone do not prove correct totals.
Query measures from both views. In the example, order revenue should total 100 and item revenue 100. Add order ID to inspect per-order results and missing or repeated orders.
Open the Explore’s SQL tab to inspect the `FROM`, join condition, filters, and grouping. Use SQL Runner or the database explain plan if needed.
If a measure disappears, check keys, dialect support, and the `symmetric_aggregates` setting. If totals are too high or low, check relationship direction, key uniqueness, join condition, and filters.
This is a documentation-based checklist, not a test performed against a particular Looker instance. Check key uniqueness in the database, then verify the generated SQL and results with your own connection, dialect, and model. Recheck any join filters or user-specific access conditions that affect the report.
Sources
[Working with joins in LookML](https://docs.cloud.google.com/looker/docs/working-with-joins?hl=en)
[Join parameters](https://docs.cloud.google.com/looker/docs/reference/param-explore-join)
[Getting the relationship parameter right](https://docs.cloud.google.com/looker/docs/best-practices/how-to-use-the-relationship-parameter-correctly?hl=en)
[Understanding symmetric aggregates](https://docs.cloud.google.com/looker/docs/best-practices/understanding-symmetric-aggregates)
[The symmetric_aggregates parameter](https://docs.cloud.google.com/looker/docs/reference/param-explore-symmetric-aggregates)
[The primary_key parameter](https://docs.cloud.google.com/looker/docs/reference/param-field-primary-key)
[Troubleshoot measures missing from a join](https://docs.cloud.google.com/looker/docs/best-practices/how-to-troubleshoot-when-measures-dont-come-through-a-join)
[How Looker generates SQL](https://docs.cloud.google.com/looker/docs/how-looker-generates-sql)
[Looker IDE overview](https://docs.cloud.google.com/looker/docs/looker-ide?hl=en)
[Looker glossary](https://docs.cloud.google.com/looker/docs/glossary?hl=en)