Tuesday, December 27, 2011

mysql select condition and sum select

When one select some records from a table, if the condition didnt meet, there will be 0 records returned..
But for a sum record, there will be min 1 record return, even if the record is not found.

SELECT * FROM `table` WHERE 1=2
#return 0 records;

SELECT id, sum(field1) FROM `table` WHERE 1=2
#return min 1 record, even if id is null

No comments: