MySQL: NULL to 0 or any other value

Converting null to 0 or any other value in mysql


Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.

usage :

SELECT COALESCE(colname, 0);

how it works:

Parameter can be a table column or a static value, if table column name is given it searches for column value in database, if column value is not null it will return column value other wise it wil look for next value in paramteres and continues until it finds out a not null value


if column name is null it will return 0, as 0 is next not null value in parameters

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s