> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

# on_sql

> Specifies the SQL condition that determines how to perform the join.

This parameter specifies the SQL condition that determines how rows from the source view and joined view are matched together. It supports simple equality joins as well as complex join conditions.

## Syntax

```yaml theme={null}
on_sql: <sql_join_condition>
```

## Properties

<ParamField path="on_sql" type="string" required>
  The SQL condition for matching rows between views. Use `${view_name.field_name}` syntax to reference fields.

  <Tip>
    When using aliased joins, both the original view names ([`join_from_view`](/modeling/relationships/parameters/join-from-view), [`join_to_view`](/modeling/relationships/parameters/join-to-view)) and aliased view names ([`join_from_view_as`](/modeling/relationships/parameters/join-from-view-as), [`join_to_view_as`](/modeling/relationships/parameters/join-to-view-as)) can be used in this parameter.
  </Tip>
</ParamField>

## Examples

```yaml title="Basic equality join" highlight={5} theme={null}
- join_from_view: buyers
  join_to_view: user_facts
  join_to_view_as: buyer_facts
  join_type: always_left
  on_sql: ${buyers.id} = ${buyer_facts.id}
  relationship_type: one_to_one
```

```yaml title="Complex inequality join" highlight={4} theme={null}
- join_from_view: table_1
  join_to_view: table_2
  join_type: always_left
  on_sql: ${table_1.id} > ${table_2.id}
```

```yaml title="Compound join keys" highlight={4} theme={null}
- join_from_view: table_1
  join_to_view: table_2
  join_type: always_left
  on_sql: ${table_1.key_1} = ${table_2.key_1} AND ${table_1.key_2} = ${table_2.key_2}
```
