Coalesce in SQL

Coalesce is a SQL function used for handling NULL values. It returns the first non-null expression from the list. Each expression is evaluated for being NULL or not and the first non-null expression will be returned as the output. It takes at least two arguments in the list.

COALESCE(expr 1,expr 2,....,expr n)
expr1, expr,2, expr n represents the values in the list.
Select Coalesce(Null,Null,1)
Result- 1
Select Coalesce(Null,'Hello', Null, 'World',Null)
Result- Hello
Select Coalesce(Null,10,'Hello',Null)
Result- 10

Leave a Reply

%d bloggers like this: