Sobes.tech
Intern

NULL

sobes.tech AI

Answer from AI

If there are no records in the orders table, the query SELECT SUM(amount) FROM orders; will return NULL, not 0. This is because aggregate functions like SUM return NULL when there are no rows to aggregate.

To get 0 instead of NULL, you can use the COALESCE construct:

SELECT COALESCE(SUM(amount), 0) FROM orders;