A method for executing a query to access data stored in a database,
wherein the query includes a plurality of DISTINCT keys, is disclosed.
The method of the present invention includes providing a first DISTINCT
operation on a first DISTINCT key, storing data fetched from the first
DISTINCT operation in a master workfile if more than one sort process is
needed to execute the query, and utilizing the master workfile to perform
subsequent DISTINCT operations for the other DISTINCT keys.