Min(column) with nulls

oracle

I am new to databases, but I hope you can help me to understand something.

Take part of this query:

select min(date) as date…

Assume that some of the dates are null. What effect would it have? Would the query break?

Best Answer

MIN will return the smallest non-NULL value. The query won't throw an error, it will simply ignore the NULL values

SQL> with x as (
  2    select null dt from dual union all
  3    select sysdate from dual
  4  )
  5  select min(dt)
  6    from x;

MIN(DT)
---------
21-OCT-11