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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.omni.co/feedback

```json
{
  "path": "/modeling/topics/parameters/always-where-sql",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# always_where_sql

> Applies a filter to all rows in a query using SQL.

Applies a filter to all rows in a query using SQL. This parameter is functionally identical to [`always_where_filters`](/modeling/topics/parameters/always-where-filters), but uses SQL instead of [filter syntax](/modeling/filters).

When defined, a filter will be inserted into the `WHERE` clause of the generated SQL block of all queries in the topic. Users with the **Querier** role can't change this filter and it will be visible only in the underlying SQL of any queries. This filter is additive to any filters specified in the workbook. For optional filter conditions, use [`default_filters`](/modeling/topics/parameters/default-filters).

This parameter is useful for removing invalid data from the topic, such as deleted records or internal testing.

Conditions should be written using `${}` syntax to reference fields defined in Omni.

<Tip>
  You can generate a syntactically correct condition using the workbook:

  1. In a workbook, add the filter using the UI.
  2. Click the **SQL** button near the top-right corner of the page.
  3. Copy the content of the `WHERE` clause.
  4. Paste the contents into the `always_where_sql` parameter.
</Tip>

## Syntax

```yaml theme={null}
always_where_sql: "<sql_condition>"
```

## Properties

<ParamField path="always_where_sql" type="string">
  A SQL condition that is applied to all queries in the topic. Use `${}` syntax to reference fields defined in Omni (e.g., `${view_name.field_name}`).
</ParamField>

## Examples

### Filter rows by a static condition

```yaml theme={null}
always_where_sql: ${order_items.sale_price} != 0
```

### Filter rows using user attributes

You can reference [user attributes](/administration/users/attributes) with `{{omni_attributes.<name>}}` to enforce per-user row-level filtering.

Filter rows to the current user's brand:

```yaml theme={null}
always_where_sql: ${products.brand} = '{{omni_attributes.brand_name}}'
```

Filter rows to the current user's email using the built-in `omni_user_email` attribute:

```yaml theme={null}
always_where_sql: ${orders.user_email} = '{{omni_attributes.omni_user_email}}'
```
