# Combining mid-flow lookups with the payload

*MuleSoft Developer Study Guide · Using Connectors · Last updated October 28, 2026 · https://www.certifyforce.com/study-guide/mulesoft-developer/using-connectors/combining-mid-flow-lookups-with-the-payload*

How to fetch extra data mid-flow without losing the payload (a target on the operation or Flow Reference, Query Single for one record) and how to combine it in DataWeave with join, leftJoin, mergeWith, ++ and a filtered map, predicting each output exactly.

- Certification: Salesforce MuleSoft Developer
- Exam section: Using Connectors
- Study guide: https://www.certifyforce.com/study-guide/mulesoft-developer

**Official exam objective:**

> Apply correct processors/syntax to retrieve and combine data in the middle of a flow, and predict outcomes.

## What the exam expects

- Retrieve data mid-flow (Database, HTTP, File or a referenced flow) while keeping the current payload, and say where the result lands.
- Pick Query Single or Select for a lookup and predict what `vars.x.name` returns for each.
- Combine the payload with the stored result using `join`, `leftJoin`, `mergeWith`, `++` or a filtered `map`, and predict the exact output.
- Store a streamed lookup result so it is consumed promptly and can be used later.
- Key terms: **target variable** (variable that receives an operation's result while the message passes on unchanged); **Target Value** (expression evaluated against the result before storing); **join / leftJoin** (pair array items by matching IDs into `l`/`r` objects); **mergeWith** (object merge where the right-hand key wins); **dynamic element** (parenthesised object or array of objects whose pairs are added to an enclosing object).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Operation with a target | Passes on the same message it received | [Enrich Data with Target Variables](https://docs.mulesoft.com/mule-runtime/latest/target-variables) |
| Target Value default | `payload`; `#[message]` stores payload and attributes | [Enrich Data with Target Variables](https://docs.mulesoft.com/mule-runtime/latest/target-variables) |
| Flow Reference with a target | Payload and variable changes in the referenced flow revert | [Flow Reference Component](https://docs.mulesoft.com/mule-runtime/latest/flowref-about) |
| Query Single | Always one result, whatever the query matches | [Query a Single Record from a Database Example](https://docs.mulesoft.com/db-connector/latest/database-connector-query-single) |
| Selector on an array | Applies to all Object values inside the array, returning an array | [DataWeave Selectors](https://docs.mulesoft.com/dataweave/latest/dataweave-selectors) |
| `join` | Only matching pairs, keys `l` and `r` | [join](https://docs.mulesoft.com/dataweave/latest/dw-arrays-functions-join) |
| `leftJoin` | Every left item; `r` only where matched | [leftJoin](https://docs.mulesoft.com/dataweave/latest/dw-arrays-functions-leftjoin) |
| `mergeWith` shared key | Right-hand pair kept, left-hand pair removed | [mergeWith](https://docs.mulesoft.com/dataweave/latest/dw-objects-functions-mergewith) |
| `++` on objects | Combines all key-value pairs of both objects | [++](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-plusplus) |
| Dynamic element | Parenthesised object or array of objects adds its pairs | [DataWeave Types](https://docs.mulesoft.com/dataweave/latest/dataweave-types) |
| Unconsumed stored stream | Holds connections until consumed or the event completes | [Streaming in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/streaming-about) |

## Check yourself

- Which approach does MuleSoft recommend over calling `lookup()` inside DataWeave, and what is `lookup`'s status?
- When should you choose `leftJoin` over `join`?
- Why does `leftJoin` on the page's four users return five items?
- What must a dynamic element's expression return?

## Sources

- [Enrich Data with Target Variables](https://docs.mulesoft.com/mule-runtime/latest/target-variables)
- [Merge Fields from Separate Objects](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-merge-multiple-payloads)
- [join](https://docs.mulesoft.com/dataweave/latest/dw-arrays-functions-join)
- [leftJoin](https://docs.mulesoft.com/dataweave/latest/dw-arrays-functions-leftjoin)
- [mergeWith](https://docs.mulesoft.com/dataweave/latest/dw-objects-functions-mergewith)
- [++](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-plusplus)
- [DataWeave Types](https://docs.mulesoft.com/dataweave/latest/dataweave-types)
- [Flow Reference Component](https://docs.mulesoft.com/mule-runtime/latest/flowref-about)
- [Mule Event Structure](https://docs.mulesoft.com/mule-runtime/latest/about-mule-event)
- [Query a Single Record from a Database Example](https://docs.mulesoft.com/db-connector/latest/database-connector-query-single)
- [Query a Database Examples](https://docs.mulesoft.com/db-connector/latest/database-connector-select)
- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/latest/dataweave-selectors)
- [Streaming in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/streaming-about)
- [lookup](https://docs.mulesoft.com/dataweave/latest/dw-mule-functions-lookup)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 9 linked practice questions, and unlimited timed mock exams are included with the MuleSoft Developer pack (USD $19): https://www.certifyforce.com/practice-exams
