Execute below script for create test table.
create table if not exists t1 (id1 int,id2 int);
Now, table is created, and it is empty table.
Execute below script,
select max(id1), max(id2) from t1
It will return below result(one row).
max(id1) max(id2)
----------- --------
<null> <null>
Execute below script,
select max(id1), max(id2) from t1 group by id1,id2
It will return below result(no result).
max(id1) max(id2)
----------- --------
Is there somebody explain the reason?
The documentation says:
The
max()aggregate function returns the maximum value of all values in the group. [...] Aggregatemax()returnsNULLif and only if there are no non-NULLvalues in the group.
In your first query, there is one group which does not have any records.
In your second query, there is no group.
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