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

# Merge queries

> Combine two explores into one result by joining them on a shared field

<Info>
  <Badge icon="test-pipe-2" color="orange" size="sm" shape="pill">Experimental</Badge> Merge queries are available to design partners behind the `merge-queries` feature flag, and the flow, limits and wording on this page may change between releases. Contact [Lightdash support](mailto:support@lightdash.com) to enable it for your organization. [What Experimental means](/support/feature-maturity-levels).
</Info>

A merge query puts two explores side by side in one result. You pick the fields you want from each explore, say which field lines them up, and run. The merged result behaves like any other chart: you can configure it, save it, add it to dashboards, schedule it, and filter it from a dashboard.

Use it when a question spans two explores that share a field at the same grain, such as review sentiment next to return rates for the same product, or orders next to payments for the same month.

<Frame caption="Merging Orders with Payments by month, from an explore to merged results">
  <img src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/merge-flow.gif?s=2711a9bab18a50c97f0134dd015c4e50" alt="Screen recording of adding a second explore to a query, choosing the join field and running the merged query" width="1000" height="625" data-path="images/explore/merge-queries/merge-flow.gif" />
</Frame>

## Before you start

Each side of a merge is a normal explore query with its own metrics, dimensions and filters. Both explores must be in the same project. You need:

* **A shared field.** A dimension that exists on both sides with matching values, such as a product code or a month. This becomes the join key. A merge can join on more than one field.
* **Matching grain.** Every dimension you select from a side must be one of the join keys. This keeps each side to one row per key, so the join never multiplies rows. See [how the join stays honest](#how-the-join-stays-honest).

Anyone who can run queries in the explore can merge. There is nothing to install and no change to your dbt project.

## Merge two explores

<Steps>
  <Step title="Build the first side as usual">
    Open an explore and pick the fields you want from it. Filters you add here apply to this side only.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/explore-with-fields.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=a83e02b438394ee7fd03fecb8ed72aea" alt="The Orders explore with Order date month and Total order amount selected" width="2880" height="1800" data-path="images/explore/merge-queries/explore-with-fields.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/explore-with-fields-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=74e01e867a4e585d1ad6c9e42dfdc672" alt="The Orders explore with Order date month and Total order amount selected" width="2880" height="1800" data-path="images/explore/merge-queries/explore-with-fields-dark.png" />
    </Frame>
  </Step>

  <Step title="Choose Merge another query">
    Open the query options menu, the `···` button next to the explore name at the top of the field panel, and choose **Merge another query**.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/merge-another-query-menu.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=a3299a32639c1f71cbf20ae5afc62a61" alt="The query options menu with the Merge another query item" width="1360" height="260" data-path="images/explore/merge-queries/merge-another-query-menu.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/merge-another-query-menu-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=9ff36ea028ce06b1ae1d18a821e42121" alt="The query options menu with the Merge another query item" width="1360" height="260" data-path="images/explore/merge-queries/merge-another-query-menu-dark.png" />
    </Frame>
  </Step>

  <Step title="Choose the second explore">
    The field panel switches to a **Data sources** view. Your first explore is listed with its selected fields, and a new card asks you to choose data to combine. Search the table list and pick the second explore.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/choose-data-to-combine.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=6e497e3a74808a7bd31861345f47d522" alt="The Data sources panel listing Orders and a Choose data to combine card above a searchable table list" width="1110" height="1660" data-path="images/explore/merge-queries/choose-data-to-combine.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/choose-data-to-combine-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=64f83f426594022fc2ec0b70efc98f30" alt="The Data sources panel listing Orders and a Choose data to combine card above a searchable table list" width="1110" height="1660" data-path="images/explore/merge-queries/choose-data-to-combine-dark.png" />
    </Frame>
  </Step>

  <Step title="Pick fields from the second side">
    You see the second explore's field tree. Add at least one metric. The **Relationship** card tells you what is still missing.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/second-source-chosen.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=3644c165ec73b5fae2a98b1cb27f01fa" alt="Payments chosen as the second source, with the Relationship card asking for at least one metric from Payments" width="2880" height="900" data-path="images/explore/merge-queries/second-source-chosen.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/second-source-chosen-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=b06d8f5672fb6dcd30030a32e52136d2" alt="Payments chosen as the second source, with the Relationship card asking for at least one metric from Payments" width="2880" height="900" data-path="images/explore/merge-queries/second-source-chosen-dark.png" />
    </Frame>
  </Step>

  <Step title="Set the join field on each side">
    In the **Relationship** card, each side has a field picker that offers dimensions only. The first side is prefilled with the dimension you already selected. Choose the matching field on the second side. Use **Add join condition** when the sides match on more than one field.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/join-field-picker.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=d7e2329b839e44cc6d2b00c8101ff1b7" alt="The Payments join field picker open, offering Order date month" width="2030" height="640" data-path="images/explore/merge-queries/join-field-picker.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/join-field-picker-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=e3e567fc6d988210cd4ce1e87bf91cb5" alt="The Payments join field picker open, offering Order date month" width="2030" height="640" data-path="images/explore/merge-queries/join-field-picker-dark.png" />
    </Frame>
  </Step>

  <Step title="Choose the join type">
    The summary next to **Relationship** reads the join back in words. The default is a full outer join. See [which join type to choose](#which-join-type-to-choose).

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/relationship-card.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=270629775c71c4fecae1781157122db9" alt="The Relationship card with both join fields set to Order date month and the Left join type selected" width="2030" height="700" data-path="images/explore/merge-queries/relationship-card.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/relationship-card-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=3036712c80eb31b80945b56f29294f46" alt="The Relationship card with both join fields set to Order date month and the Left join type selected" width="2030" height="700" data-path="images/explore/merge-queries/relationship-card-dark.png" />
    </Frame>
  </Step>

  <Step title="Run the query">
    Results arrive as one table. The join key has a key icon, and every other column carries the name of the explore it came from. Configure the chart the way you would for any explore.

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/merged-results.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=bfb853cbe9d1f289d743657ba8013805" alt="Merged results with Order date month, Total order amount from Orders and Unique payment count from Payments" width="2880" height="1800" data-path="images/explore/merge-queries/merged-results.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/merged-results-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=fc126da4610b01f94977eb9a6c4deec9" alt="Merged results with Order date month, Total order amount from Orders and Unique payment count from Payments" width="2880" height="1800" data-path="images/explore/merge-queries/merged-results-dark.png" />
    </Frame>
  </Step>

  <Step title="Save the chart">
    **Save chart** works as it does for any chart. The saved chart shows the relationship at the top and can be added to dashboards and [scheduled deliveries](/explore/create-scheduled-deliveries).

    <Frame>
      <img className="block dark:hidden" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/saved-merged-chart.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=86fedca1baae307f6a1323e1b4fd91bc" alt="A saved merged chart with a header reading Orders + Payments, matched on Order date month" width="2880" height="1800" data-path="images/explore/merge-queries/saved-merged-chart.png" />

      <img className="hidden dark:block" src="https://mintcdn.com/lightdash/NSqFrk0onSkMurhz/images/explore/merge-queries/saved-merged-chart-dark.png?fit=max&auto=format&n=NSqFrk0onSkMurhz&q=85&s=10da7d84526bf9a52b3de1d77e3b4d73" alt="A saved merged chart with a header reading Orders + Payments, matched on Order date month" width="2880" height="1800" data-path="images/explore/merge-queries/saved-merged-chart-dark.png" />
    </Frame>
  </Step>
</Steps>

## Which join type to choose

The three options answer one question: when a key exists on only one side, what happens to it?

| Join type      | Keeps                                                                                        | Use when                                           |
| -------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| **Inner**      | Only keys present on both sides. Anything unmatched is dropped.                              | A row without both measures would be misleading.   |
| **Left**       | Every key from the first explore. The second side's columns are blank where it has no match. | The first explore is the list you report on.       |
| **Full outer** | Every key from either side. Blanks wherever one side has nothing.                            | You want to spot keys that exist on one side only. |

## How the join stays honest

A merge is only safe when each side has exactly one row per join key. Because an explore query groups by its dimensions, that comes down to one rule: **every dimension you select on a side must be a join key.** Metrics are already one value per key, so any number of them is fine.

When a selection breaks the rule, the query refuses with a message rather than multiplying rows. Either add that dimension as another join condition on both sides, or remove it.

For example, reviews by `product` merged with returns by `product`, joined on product, works. Reviews by `product` and `month` merged with returns by `product`, joined on product only, refuses, because the review side has many rows per product. Add `month` to both sides and to the join conditions and it works again.

## Filters

Filters on either side apply to that side before the join. A [dashboard filter](/explore/dashboards/filter) on a merged chart is pushed into both sides, so a date filter narrows both explores rather than only the merged output.

## Current limits

| Area                | Today                                                                                                                                                                                 |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Table calculations  | Work on fields from one side. A calculation that mixes fields from both sides is not yet supported.                                                                                   |
| Custom metrics      | Available on the first explore. Custom metrics defined on the second side are not yet supported.                                                                                      |
| Join key formatting | The merged key column shows its underlying value. A month key shows as a full date rather than a month label.                                                                         |
| Row limits          | Each side runs with its own row limit. If a side is cut off by its limit, the merge refuses instead of returning a partial answer. Narrow that side with a filter or raise its limit. |
| Sources             | Two explores from the same project.                                                                                                                                                   |
