Fixed missing order of last entry SQL