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

# Query

> Run a SQL query to transform data.

The **Data Query** step lets you execute a SQL query to fetch, filter, or transform your input data. Use this step to:

* **Enrich data:** Join your input data with additional tables to add extra context.
* **Refetch information:** Retrieve the most up-to-date data after a **Wait step**.
* **Filter rows:** Apply custom conditions to include or exclude specific records.
* **Fan-out:** Expand a single trigger event into multiple notifications by transforming the input row into multiple rows.

To add a **Data Query** step, click the "+" placeholder node in the builder or the "+" button on any connection between two steps, then select **Data Query**.

<Frame caption="Configuration of a Data Query step that enriches user data by joining with the organization table.">
  <img src="https://mintcdn.com/notikaai/k35ntJQ2S6c87rnB/images/querystep.png?fit=max&auto=format&n=k35ntJQ2S6c87rnB&q=85&s=199dc834575edc61f1cd0ed4eb1ff079" alt="Data Query interface" width="3454" height="1986" data-path="images/querystep.png" />
</Frame>

## Breakdown

<Steps>
  <Step title="Select a database connection" icon="database">
    Choose the database connection through which the query will be executed. This connection must be configured in your settings.
  </Step>

  <Step title="Write your SQL query" icon="file-code">
    Enter a SQL statement that processes the data from the parent step. You can access the input data via a temporary table called `input_rows` in addition to the tables from the database connection you selected.

    The query editor supports SQL syntax highlighting, auto-completion, and a built-in formatter.

    <Accordion title="Example">
      Suppose the parent step returns user details with columns like `email` and `organization_id`, and you want to bring in
      the user's organization name for a notification template. You can write a query to join these rows with an organization table to
      enrich the data:

      ```sql theme={null}
      SELECT input_row.*,
            org.organization_name
      FROM input_rows AS input_row
      JOIN organization AS org
        ON input_row.organization_id = org.id;
      ```

      In this query:

      * **input\_rows:** Contains all data passed from the previous step.
      * **organization:** The table in your database that contains the organization name.
    </Accordion>
  </Step>

  <Step title="Add a description (optional)" icon="info">
    Provide a brief description to easily identify this step within your workflow.
  </Step>

  <Step title="Test the query output" icon="flask">
    Use the Test Panel to preview outputs and validate your query. This ensures that the data passed on to subsequent steps meets your requirements.
  </Step>
</Steps>

## Explore further

<CardGroup cols={2}>
  <Card title="How it works" icon="gears" href="/docs/getting-started/how-it-works">
    Discover how our real-time engine executes your queries and manages data
    transformations.
  </Card>

  <Card title="Publishing workflows" icon="rocket" href="/docs/workflow/publishing-workflows">
    Learn how publishing your workflow activates the Data Query step and
    finalizes its configuration.
  </Card>
</CardGroup>
