I don't have DB2 to test this on. But I think it depends. The following statement:
select max(1)
from (select 1 as i)t
where i = 2
Produces different results on SQL Server (null
) and MySQL (1). If DB2 returns 1
, then the statements are different. I would expect it to return null
, though.
If it returns null
, then the two statements are the same in effect. However, the max()
statement is likely to perform less well than the exists
. The exists
statement can stop at the first matching value.