fixed bug with sql select