Skip to content
Advertisement

choose minimum date from a record out of multiple columns

Hi I have the following table struct:

and i want to choose the minimum Date between Date1 and Date(n) (20 dates in my case). So for example it would choose Date1 for Person1 and Date2 for Person2.

obviously i can just use min(Date) if I only have 1 date columns, but I can’t get my logic right in this case.

Thanks very much.

Advertisement

Answer

Least() should ignore NULLs, if present. (the above works for Postgres)

UPDATE (thanks to @WarrenT) apparently DB2 does not have LEAST(), but it does have MIN() instead (having more than one argument).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement