fixed error in sql query