VMS Help  —  RDML72  Statements  UNIQUE  Examples
    The following programs demonstrate the use of the UNIQUE
    conditional expression. These programs join the relations
    EMPLOYEES and DEGREES over their common field, EMPLOYEE_ID. The
    UNIQUE expression limits the record stream to those records in
    the EMPLOYEES relation that have only one corresponding record
    in the DEGREES relation. These programs print an informational
    message and the selected employees first and last name in
    alphabetical order, based on the last name.

1  –  C Example

    #include <stdio.h>
    DATABASE PERS = FILENAME "PERSONNEL";

    main()
    {
    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
        SORTED BY E.FIRST_NAME
        WITH UNIQUE D IN DEGREES WITH D.EMPLOYEE_ID = E.EMPLOYEE_ID
           printf("%s %s has one and only one college degree.\n",
                         E.FIRST_NAME, E.LAST_NAME);
    END_FOR;

    COMMIT;
    FINISH;
    }

2  –  Pascal Example

    program unique_expr (input,output);
    DATABASE PERS = FILENAME 'PERSONNEL';

    begin
    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
       WITH UNIQUE D IN DEGREES WITH D.EMPLOYEE_ID = E.EMPLOYEE_ID
          writeln (E.FIRST_NAME, ' ', E.LAST_NAME,
                  ' has one and only one college degree.');
    END_FOR;

    COMMIT;
    FINISH;
    end.
Close Help