Minor buggfix in sql query