mysql - Why does SQL NOT EXISTS return 1 record of all NULL values -


sql fiddle on following:

create table tbl( col1 int, col2 int, col3 int); insert tbl values(1,1,1); insert tbl values(1,1,1);  select sum(col1) c1, sum(col2) c2, sum(col3)c3 tbl not exists (   select 2 c1, 2 c2, 2 c3   ) 

i expecting return 0 records. instead returns 1 record of null values. can tell me why?

p.s. trying understand not exists behavior.

it's not exists. not exists evaluates false, since select 2 c1, 2 c2, 2 c3 returns row. means query equivalent to:

select sum(col1) c1, sum(col2) c2, sum(col3) c3 tbl 0 

saying that, sum semantics. sum in empty set should return value, , value in case null.

from mysql documentation:

sum(expr)

returns sum of expr. if return set has no rows, sum() returns null.

sum() returns null if there no matching rows.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -