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

# anyIf

> Example of using the anyIf combinator

<h2 id="description">
  Description
</h2>

The [`If`](/reference/functions/aggregate-functions/combinators#-if) combinator can be applied to the [`any`](/reference/functions/aggregate-functions/any)
aggregate function to select the first encountered element from a given column
that matches the given condition.

<h2 id="example-usage">
  Example usage
</h2>

In this example, we'll create a table that stores sales data with success flags,
and we'll use `anyIf` to select the first `transaction_id`s which are above and
below an amount of 200.

We first create a table and insert data into it:

```sql title="Query" theme={null}
CREATE TABLE sales(
    transaction_id UInt32,
    amount Decimal(10,2),
    is_successful UInt8
) 
ENGINE = MergeTree()
ORDER BY tuple();

INSERT INTO sales VALUES
    (1, 100.00, 1),
    (2, 150.00, 1),
    (3, 155.00, 0),
    (4, 300.00, 1),
    (5, 250.50, 0),
    (6, 175.25, 1);
```

```sql theme={null}
SELECT
    anyIf(transaction_id, amount < 200) AS tid_lt_200,
    anyIf(transaction_id, amount > 200) AS tid_gt_200
FROM sales;
```

```response title="Response" theme={null}
┌─tid_lt_200─┬─tid_gt_200─┐
│          1 │          4 │
└────────────┴────────────┘
```

<h2 id="see-also">
  See also
</h2>

* [`any`](/reference/functions/aggregate-functions/any)
* [`If combinator`](/reference/functions/aggregate-functions/combinators#-if)
