0

My Query for today is that I wanted to set my MySQL value to zero whenever an empty string is saved. Is there a way to do this without using trigger? What I wanted is like this in the illustration

          TABLE DATA                                   MYSQL TABLE VALUE
name    age    years of experience      -->            name    age    yrs
John    23                              -->            John    23      0   
3
  • set the default value to 0 for that field Commented Feb 27, 2014 at 9:35
  • Already did, but stil no luck Commented Feb 27, 2014 at 9:38
  • 2
    use the default + an update script running the IFNULL() example from the answer to correct already existing entires in your db Commented Feb 27, 2014 at 9:53

1 Answer 1

1

Set the field to stay NULL if hs no value

ALTER DATA MODIFY years_of_experience varchar(255) null;

And try this:

select name,age,IFNULL(years_of_experience,0) from DATA;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.