. . . "All the data needed to do the sort of course needs to be in the database, and you need to determine the best way to join the various tables so the data can be sorted properly." .