Sql where or bug fix