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

# Query

> Run custom SQL queries against your data warehouse

Executes a custom SQL query against your connected data warehouse and uses the results as a data source in your workflow. Use it when you need to pull data using complex SQL that goes beyond what Get Data provides.

## Configuration

| Setting                 | Description                                                  |
| ----------------------- | ------------------------------------------------------------ |
| **Query**               | SQL SELECT statement to execute against the data warehouse   |
| **DWH Auth ID**         | Data warehouse authentication ID (default: 0)                |
| **Result Fields**       | Expected result columns and types (auto-detected if omitted) |
| **Virtual Object Name** | Namespace prefix for output fields (default: `query`)        |

### Result Field Types

| Type         | Description    |
| ------------ | -------------- |
| **str**      | String/text    |
| **int**      | Integer        |
| **float**    | Decimal number |
| **bool**     | Boolean        |
| **date**     | Date           |
| **datetime** | Date and time  |

## How It Works

<Steps>
  <Step title="Write your SQL query">
    Write a SELECT statement using your DWH's SQL syntax. Reference tables with bare names, schema-qualified names (`"schema"."table"`), or fully qualified names.
  </Step>

  <Step title="Define result fields (optional)">
    Specify expected output columns and their types. If omitted, BonData auto-detects them from the query results.
  </Step>

  <Step title="Use as a data source">
    The query results become the starting point for your workflow, available as **Mentions** in downstream nodes.
  </Step>
</Steps>

## Output

A dataset containing the query results. Each column becomes available as a **Mention** in downstream nodes, named as `{virtual_object_name}.{column_name}`.

<Note>
  The Query node acts as a workflow starting point - it does not have an input. Only SELECT statements are supported.
</Note>

## Example

Pull a custom report from Snowflake:

```sql theme={null}
SELECT
  account_id,
  account_name,
  SUM(revenue) as total_revenue,
  COUNT(DISTINCT contact_id) as contact_count
FROM accounts
JOIN contacts ON accounts.id = contacts.account_id
WHERE created_at > '2024-01-01'
GROUP BY account_id, account_name
HAVING SUM(revenue) > 10000
```

## Best Practices

* Use Query when you need JOINs, aggregations, or complex WHERE clauses that Get Data doesn't support
* Specify **Result Fields** explicitly for predictable downstream behavior
* Keep queries efficient - add WHERE clauses to limit the dataset size
* Test your query directly in your DWH console before using it in a workflow

## Related Nodes

* **[Get Data](/guide/nodes/data/get-data-node)** - simpler data fetching without writing SQL
* **[Code Execution](/guide/nodes/code/code-execution-node)** - run Python code for transformations that SQL can't express
* **[Transform](/guide/nodes/transform/transform-node)** - apply SQL expressions to data already in the workflow
