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

# fact_treble_session_variables

> Variables captured or set during each conversation flow.

# fact\_treble\_session\_variables

Each row is one variable of one conversation flow: data captured from the user's answers, set by the flow logic, or passed in when the conversation was created via API. Join with `fact_treble_sessions` through `session_id` to add flow, contact, and outcome context.

## What questions does it answer?

* What values did users provide for a given field (email, order id, city…)?
* Which sessions carry a given variable, and with which value?
* How do outcomes differ by a variable's value (join back to sessions)?

## Columns

| Column           | Type       | Description                                    |
| ---------------- | ---------- | ---------------------------------------------- |
| `session_id`     | Int64      | The conversation flow this variable belongs to |
| `company_id`     | Int32      | Your company (filtered automatically)          |
| `variable_name`  | String     | Variable name as defined in the flow           |
| `variable_value` | String     | Current value (last write wins)                |
| `created_at`     | DateTime64 | When the variable was first set                |
| `updated_at`     | DateTime64 | When it was last updated                       |
| `synced_at`      | DateTime64 | When this row was last written/corrected       |

<Note>
  When a flow overwrites a variable, the existing row is updated in place — you see its **latest** value. In rare cases a flow records the same variable name as separate entries; when that matters, keep the row with the highest `updated_at` (as the example below does).
</Note>

## Example queries

### Pivot variables into columns for one flow

```sql theme={null}
SELECT
    session_id,
    argMaxIf(variable_value, updated_at, variable_name = 'email')    AS email,
    argMaxIf(variable_value, updated_at, variable_name = 'order_id') AS order_id
FROM fact_treble_session_variables
WHERE session_id IN (
    SELECT session_id FROM fact_treble_sessions
    WHERE poll_id = {your_poll_id} AND created_at >= today() - 30
)
GROUP BY session_id
```

### Sessions by a variable's value

```sql theme={null}
SELECT variable_value AS city, count() AS sessions
FROM fact_treble_session_variables
WHERE variable_name = 'city'
  AND created_at >= today() - 30
GROUP BY city
ORDER BY sessions DESC
```
