History - sql query fix, data display fix