lundi 30 avril 2018

Print a new column with conditional contraints using if statement in MySql

I have a table 'actor' whose fields are 'pk','fname',lname. I want to print a column(lets call this name) where by default fname is printed but if fname is null then lname is printed.

The query that I used is:

select if(fname = null,lname,fname) as name from actor;

This however does not achieve the given task. It prints the fname even if the value is null.

Aucun commentaire:

Enregistrer un commentaire