Refactors Response sql query.