Search code examples
mysqlconditional-operator

How to implement ternary conditional operator in MySQL


I want to implement ternary conditional operator in MySQL. I have a table in which one field id exist. Its value may be null. I want to display id in ternary conditional format like this:

select id = id == null ? 0 : id;

Is it possible in MySQL?


Solution

  • Try this :

    select if(Id is null, 0, id) as Id;