COALESCE()is used when we want to return a default value when there is null in the the table
Eg: Select revenue – Coalesce (cost price, 0) as profit from table_name
Any amateur SQL person would think Why to use COALESCE , when we have ISNULL function in SQL. This is because when we have multiple values , and not sure they might be null , then we opt for COALESCE. It return the first non-null value in a list.
Answers ( 3 )
COALESCE()is used when we want to return a default value when there is null in the the table
Eg: Select revenue – Coalesce (cost price, 0) as profit from table_name
Any amateur SQL person would think Why to use COALESCE , when we have ISNULL function in SQL. This is because when we have multiple values , and not sure they might be null , then we opt for COALESCE. It return the first non-null value in a list.
For e.g.
emp_vehicle_count = NULL
emp_mobile_count = NULL
emp_count = 200
SELECT COALESCE(emp_vehicle_count, emp_mobile_count,emp_count);
Output : 200
Coalesce() function is used to handle NULL values.
During the evaluation process, the NULL values are replaced with the user-defined value.