The following programs demonstrate the use of the FIRST FROM clause. The programs find the first record in the JOBS relation with the value "Company President" in the field JOB_TITLE. Using this record's value for JOB_CODE, these programs create a record stream containing the records in the CURRENT_JOB relation that have this same job code. The programs print the value that the first record from this record stream holds in the LAST_NAME field.
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; DECLARE_VARIABLE name SAME AS PERS.CURRENT_JOB.LAST_NAME; main() { READY PERS; START_TRANSACTION READ_ONLY; GET name = FIRST C.LAST_NAME FROM C IN CURRENT_JOB WITH C.JOB_CODE = FIRST J.JOB_CODE FROM J IN JOBS WITH J.JOB_TITLE = "Company President" SORTED BY C.JOB_CODE; END_GET; printf ("Last name is %s", name); COMMIT; FINISH; }
2 – Pascal Example
program first_val (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; DECLARE_VARIABLE name SAME AS PERS.CURRENT_JOB.LAST_NAME; begin READY PERS; START_TRANSACTION READ_ONLY; GET name = FIRST C.LAST_NAME FROM C IN CURRENT_JOB WITH C.JOB_CODE = FIRST J.JOB_CODE FROM J IN JOBS WITH J.JOB_TITLE = 'Company President' SORTED C.JOB_CODE; END_GET; writeln ('Last name is: ', name); COMMIT; FINISH; end.