The following programs demonstrate the use of the REDUCED TO clause and the SORTED clause with a single relation. These programs sort the records in the EMPLOYEES relation on the basis of STATE. The REDUCED TO clause limits the record stream so that each record in the stream has a different value for the field STATE. The programs then display the list of states represented in the EMPLOYEES relation.
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; main () { READY PERS; START_TRANSACTION READ_ONLY; FOR E IN EMPLOYEES REDUCED TO E.STATE SORTED BY E.STATE printf("%s\n", E.STATE); END_FOR; COMMIT; FINISH; }
2 – Pascal Example
program reduced_one_rel (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; begin READY PERS; START_TRANSACTION READ_ONLY; FOR E IN EMPLOYEES REDUCED TO E.STATE SORTED BY E.STATE writeln (E.STATE); END_FOR; COMMIT; FINISH; end.