The following programs demonstrate the use of the CROSS clause to
join records from two relations (a non-equijoin). These programs
join the relations CURRENT_JOB and JOBS over their common field
JOB_CODE. This allows these programs to print a report that
contains fields from both relations. Specifically, these fields
are: LAST_NAME from the CURRENT_JOBS relation, JOB_CODE from the
JOBS relation, and JOB_TITLE from the JOBS relation.
1 – C Example
#include <stdio.h>
DATABASE PERS = FILENAME "PERSONNEL";
main()
{
READY PERS;
START_TRANSACTION READ_ONLY;
FOR C IN CURRENT_JOB
CROSS J IN JOBS OVER JOB_CODE
printf ("%s",C.LAST_NAME);
printf (" %s",J.JOB_CODE);
printf (" %s\n", J.JOB_TITLE);
END_FOR;
COMMIT;
FINISH;
}
2 – Pascal Example
program person_job (input,output);
DATABASE PERS = FILENAME 'PERSONNEL';
begin
READY PERS;
START_TRANSACTION READ_ONLY;
FOR C IN CURRENT_JOB
CROSS J IN JOBS OVER JOB_CODE
writeln (C.LAST_NAME, ' ',J.JOB_CODE, ' ',J.JOB_TITLE);
END_FOR;
COMMIT;
FINISH;
end.