Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL if not null

Tags:

sql

mysql

Is there a way to do the following without a CASE statement?

SELECT ifnotnull(field1, '!!!')

Now I'm currently doing the verbose:

CASE WHEN field1 IS NOT NULL THEN '!!!' ELSE field1 END
like image 829
David542 Avatar asked Mar 08 '23 15:03

David542


1 Answers

yes:

SELECT if(field1 is not null, '!!!', field1)

which would be the same as

SELECT if(field1 is not null, '!!!', NULL)

Documentation on IF is here.

like image 82
Alex Tartan Avatar answered Mar 20 '23 06:03

Alex Tartan