So if I had a table in my database with the values
1
2
3
4
NULL
And I executed the query
SELECT MAX(col1) FROM <table>
I'd get 4. Is there any way to change this so Null would be treated as the maximum as oppose to the minimum?
Thanks!
SELECT MAX(ISNULL(col1, 2147483647)) FROM <table>
[2147483647 = 2^31 - 1]
Just as a variant, you can do this on Oracle.
SELECT *
FROM ( SELECT col1
FROM <table>
ORDER BY col1 DESC NULLS FIRST
)
WHERE rownum = 1
(OP hasn't specified any particular flavour of database)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With