# Chalk DataFrames Reference: Joins
source: https://docs.chalk.ai/dataframe-docs#section-joins

Methods for combining two DataFrames based on matching keys.

- `join` — standard equality joins (inner, left, right, outer, semi, anti, cross)
- `join_asof` — temporal / nearest-key join for time-series data

## `join(other, on, left_on, right_on, how, right_suffix, probe_with_right_side, where)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.join

Join this [`DataFrame`](https://docs.chalk.ai/dataframe-docs#DataFrame) with another.

**Parameters**

- `other`: `DataFrame`
  Right-hand [`DataFrame`](https://docs.chalk.ai/dataframe-docs#DataFrame).
- `on`: `Mapping[str | Underscore, str | Underscore] | Sequence[str | Underscore] | None` = `None`
  Join keys. Can be specified in multiple ways:

  - A sequence of column names (same names on both sides): `on=["col1", "col2"]`
  - A mapping of left->right column names: `on={"left_col": "right_col"}`
  - If None, must specify `left_on` and `right_on` separately.
- `left_on`: `Sequence[str | Underscore] | None` = `None`
  Column names for left DataFrame join keys. Only used when `on` is None. Must be paired with `right_on`.
- `right_on`: `Sequence[str | Underscore] | None` = `None`
  Column names for right DataFrame join keys. Only used when `on` is None. Must be paired with `left_on`.
- `how`: `JoinType` = `'inner'`
  Join type. Supported values:

  - `"inner"`: Keep only rows that match in both DataFrames (default)
  - `"left"`: Keep all rows from left DataFrame
  - `"right"`: Keep all rows from right DataFrame
  - `"outer"` or `"full"`: Keep all rows from both DataFrames
  - `"semi"`: Return rows from left that have matches in right (no right columns)
  - `"anti"`: Return rows from left that have no matches in right
  - `"cross"`: Cartesian product (do not pass in `on`)
- `right_suffix`: `str | None` = `None`
  Optional suffix applied to right-hand columns when names collide. For example, if both DataFrames have a column `"value"` and `right_suffix="_right"`, the result will have `"value"` and `"value_right"`.
- `probe_with_right_side`: `bool` = `False`
  If True, the probe side of the join will be the right and the build will be the left. Default is False (left is probe, right is build)
- `where`: `Expr | None` = `None`

**Returns**

`DataFrame`

## `join_asof(other, on, left_on, right_on, by, left_by, right_by, strategy, right_suffix, coalesce)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.join_asof

Perform an as-of join with another DataFrame.

An as-of join is similar to a left join, but instead of matching on equality, it matches on the nearest key from the right DataFrame. This is commonly used for time-series data where you want to join with the most recent observation.

**Important**: Both DataFrames must be sorted by the `on` (or `left_on/right_on`) column before calling this method. Use `.order_by(on)` to sort if needed.

**Parameters**

- `other`: `DataFrame`
  Right-hand DataFrame to join with.
- `on`: `str | Underscore | None` = `None`
  Column name to use as the as-of join key (must be sorted). This column is used for both left and right DataFrames. The join finds the nearest match according to the `strategy`. Either `on` or both `left_on` and `right_on` must be specified.
- `left_on`: `str | Underscore | None` = `None`
  Column name in left DataFrame for the as-of join key. Only used when `on` is None. Must be paired with `right_on`.
- `right_on`: `str | Underscore | None` = `None`
  Column name in right DataFrame for the as-of join key. Can be used with `on` (to specify a different right column name) or with `left_on` (when `on` is None).
- `by`: `Mapping[str | Underscore, str | Underscore] | Sequence[str | Underscore] | None` = `None`
  Additional exact-match columns (optional). These columns must match exactly before performing the as-of match on the `on` column. Can be specified as:

  - A sequence of column names (same names on both sides): `by=["col1", "col2"]`
  - A mapping of left->right column names: `by={"left_col": "right_col"}`
  - If None, can specify `left_by` and `right_by` separately.
- `left_by`: `Sequence[str | Underscore] | None` = `None`
  Column names in left DataFrame for exact-match conditions. Only used when `by` is None. Must be paired with `right_by`.
- `right_by`: `Sequence[str | Underscore] | None` = `None`
  Column names in right DataFrame for exact-match conditions. Only used when `by` is None. Must be paired with `left_by`.
- `strategy`: `AsOfJoinStrategy | 'forward' | 'backward'` = `'backward'`
  Join strategy controlling which match to select:

  - `"backward"` (default): Match with the most recent past value
  - `"forward"`: Match with the nearest future value Can also pass `AsOfJoinStrategy.BACKWARD` or `AsOfJoinStrategy.FORWARD`.
- `right_suffix`: `str | None` = `None`
  Suffix to add to overlapping column names from the right DataFrame.
- `coalesce`: `bool` = `True`
  Whether to coalesce the join keys (default True).

**Returns**

`DataFrame`
