reduce sql result