HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

min(column) with nulls?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
minwithnullscolumn

Problem

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?

Solution

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

Code Snippets

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

Context

StackExchange Database Administrators Q#7080, answer score: 13

Revisions (0)

No revisions yet.