Good try , a little adjustment to your solution will be, don't change $3 because it will make it's value to variable as OLD3 which will be dangerous on the first line itself when variable OLD3 will be NULL and it will be assigned to 3rd column, then it will never be a NON-NULL value, so try.