Fix bug with mysql query