David542
David542

Reputation: 110163

MySQL if not null

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

Upvotes: 4

Views: 10532

Answers (2)

Alex Tartan
Alex Tartan

Reputation: 6836

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.

Upvotes: 10

Carlos Torres
Carlos Torres

Reputation: 419

Try COALESCE

SELECT COALESCE(field1, '!!!')

Upvotes: -3

Related Questions