sql condition to insert updated data