I'm confused on why the following SQL sentence returns one row:
#MySQL
select max(1) from dual where 0 = 1
#SQLite
select max(1) where 0 = 1
I'm really confused about this result. Can anyone please shed some light over this behavior?
Thanks in advance!
An aggregate like max without a group by always returns one row. If the underlying rowset it empty, it will return a single row with null. Otherwise, it returns the maximum of the column you specified.
The where clause affects which rows the maximum is calculated for. It does not change the fact that the query has to return a maximum.
Because MAX is a scalar function so it needs to return a result, as opposed to a table-result query.
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