## Question:

It is necessary to select the minimum value from the field, but if it turns out that it is equal to 0, then you need to take the next value … if a simple selection returns, for example, the numbers 13, 34, 5, 0, 89 – I need to get 5, and if a simple selection returns all rows with only zeros, then I need to return 0 …

Thank you

## Answer:

```
COALESCE(MIN(CASE WHEN val != 0 THEN val END), 0)
```