MySql Query Replace NULL with Empty String in Select MySql Query Replace NULL with Empty String in Select mysql mysql

MySql Query Replace NULL with Empty String in Select


If you really must output every values including the NULL ones:

select IFNULL(prereq,"") from test


SELECT COALESCE(prereq, '') FROM test

Coalesce will return the first non-null argument passed to it from left to right. If all arguemnts are null, it'll return null, but we're forcing an empty string there, so no null values will be returned.

Also note that the COALESCE operator is supported in standard SQL. This is not the case of IFNULL. So it is a good practice to get use the former. Additionally, bear in mind that COALESCE supports more than 2 parameters and it will iterate over them until a non-null coincidence is found.


Try below ;

  select if(prereq IS NULL ," ",prereq ) from test