Updating sql tables when joined