# Sorting a database

The sorting function sorts all games in a database. You can select a number of sort criteria. When two games are equal according to the the first criteria, they are sorted using the second criteria, and so on.

### Sort criteria

The available sorting criteria are:

- Date (oldest games first)
- Year (same as date, but using the year only)
- Event name
- Site name
- Country (last 3 letters of Site name)
- Round name
- White name
- Rating (average of White and Black ratings, highest first)
- Black name
- Result (White wins, then draws, then Black wins)
- Length (number of full moves in the game)
- ECO (the Encyclopedia of Chess Openings code)

### Sort results

When you sort a Scid database that is not read-only, the sort results are saved so the order of games in the database is permanently changed. If you want to the sort results to be temporary, make the database read-only first using the File: Read-only menu command.

When you sort a database that is read-only or is actually a PGN file, the sort results cannot be saved so the sorted order of games will be lost when the file is closed.

Note that sorting a database resets the search filter to contain all games.

### Important note about sorting databases:

When a database is sorted, the index file is altered but the game file is not changed. This means sorting a database will leave the game file records in a scrambled order relative to the index file. This can really slow down tree, position and material/pattern searches, so you should reorder the game file by compacting it after sorting the database to maintain good search performance.

(Updated: Scid 2.5, June 2001)