0
SELECT MIN(column) FROM table;

will return minimum from nonnull elements.

I would like to write a query that will treat NULL as if it were the smallest value possible.

I have seen tricks with dates using a special value like here: https://stackoverflow.com/a/32240382/7810882

But what if the column is of type int and there is no special value that I can map NULL to?

user7810882
  • 223
  • 1
  • 4
  • 14

1 Answers1

3

You can do this using a case expression:

SELECT (CASE WHEN COUNT(*) = COUNT(COLUMN) THEN MIN(column) END)
FROM table;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786