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

# Min/Max

> Compute the min/max value of a field

`min` and `max` return the smallest and largest values of a column, respectively.

<CodeGroup>
  ```sql Min theme={null}
  SELECT pdb.agg('{"min": {"field": "rating"}}') FROM mock_items
  WHERE id @@@ pdb.all();
  ```

  ```sql Max theme={null}
  SELECT pdb.agg('{"max": {"field": "rating"}}') FROM mock_items
  WHERE id @@@ pdb.all();
  ```
</CodeGroup>

<CodeGroup>
  ```ini Expected Response (Min) theme={null}
        agg
  ----------------
   {"value": 1.0}
  (1 row)
  ```

  ```ini Expected Response (Max) theme={null}
        agg
  ----------------
   {"value": 5.0}
  (1 row)
  ```
</CodeGroup>

See the [Tantivy documentation](https://docs.rs/tantivy/latest/tantivy/aggregation/metric/struct.MinAggregation.html) for all available options.

## SQL Min/Max Syntax

SQL's `MIN`/`MAX` syntax is supported in beta. To enable it, first run

```sql theme={null}
SET paradedb.enable_aggregate_custom_scan TO on;
```

With this feature enabled, the following query is equivalent to the above and is executed in the same way.

<CodeGroup>
  ```sql Min theme={null}
  SELECT MIN(rating) FROM mock_items
  WHERE id @@@ pdb.all();
  ```

  ```sql Max theme={null}
  SELECT MAX(rating) FROM mock_items
  WHERE id @@@ pdb.all();
  ```
</CodeGroup>

By default, `MIN`/`MAX` ignore null values. Use `COALESCE` to include them in the final sum:

```sql theme={null}
SELECT MIN(COALESCE(rating, 0)) FROM mock_items
WHERE id @@@ pdb.all();
```
