Optimized code that sorts sql command history.

Trivial change to optimize sorting of SQL history query.