refactoring SQL for repetitive run during hoanoho-update