The REDUCED TO clause lets you eliminate duplicate values for fields in a record stream. You can use this expression to eliminate redundancy in the results of a query and to group records in a relation according to unique field values.
1 – Examples
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.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; }
1.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.
2 – Format
(B)0[mreduce-clause = qqqqq> [4mREDUCED[m TO qqqwqqqqqq> db-field qqqwqqq> mqqqqqq<qqqq , <qqqqqj
2.1 – Format arguments
db-field A database field value expression. A database field value expression is a field name qualified with a context variable. The database field must be defined in the current context of the statement. For example, the database field must be defined in the context of the START_STREAM or DECLARE_STREAM statements or the FOR loop. See the DB_Field help entry for more information.