ordering sql bug fixed