some fix in sql query