Sometimes you need information from two different tables. You can accomplish this only if there is a link between the two tables. That is, a column in each table contains identical information. For example, both Q.STAFF and Q.ORG have a column that contains employee numbers. In Q.STAFF this column is ID; in Q.ORG it is MANAGER. With this link, you can combine information from both tables into one report by using the following process:
Q.STAFF | ID | NAME | DEPT | JOB | YEARS | SALARY | COMM | --------+----+-------+-------+-------+--------+---------+-------| | | | | | | | | |
Q.STAFF | ID | NAME | --------+--------+-----------| | | | |
Q.STAFF | ID | NAME | --------+--------+-----------| | | | Q.ORG | DEPTNUMB | DEPTNAME | MANAGER | DIVISION | LOCATION | ------+----------+-----------+---------+------------+----------| | | | | | | |
Q.STAFF | ID | NAME | --------+--------+-----------| | | | Q.ORG | DEPTNUMB | DEPTNAME | MANAGER | ------+----------+-----------+---------| | | | | |
Q.STAFF | ID | NAME | --------+--------+-----------| | | | Q.ORG | DEPTNUMB | DEPTNAME | MANAGER | | ------+----------+-----------+---------+------------| | | | | | |
Q.STAFF | ID | NAME | --------+--------+-----------| | _ID | _NM | Q.ORG | DEPTNUMB | DEPTNAME | MANAGER | | ------+----------+-----------+---------+------------| P. | | | _ID | _NM | |
The same example element (in this case _ID) must be used in two example tables to select only the rows where MANAGER (the manager ID) in Q.ORG is equal to ID in Q.STAFF.
P. can appear in only one table. The example element _NM is added to the unnamed column of the Q.ORG example table so that it is presented from the Q.STAFF table even though no P. appears in the Q.STAFF example table.
This query says the following: Show columns DEPTNUMB, DEPTNAME, and MANAGER from Q.ORG and the NAME column from Q.STAFF. Display the rows where the data in the MANAGER column in Q.ORG is the same as the data in the ID column in Q.STAFF.
Press the Run function key to get this report:
DEPTNUMB DEPTNAME MANAGER NAME -------- -------------- ------- --------- 20 MID ATLANTIC 10 SANDERS 38 SOUTH ATLANTIC 30 MARENGHI 15 NEW ENGLAND 50 HANES 42 GREAT LAKES 100 PLOTZ 51 PLAINS 140 FRAYE 10 HEAD OFFICE 160 MOLINARE 66 PACIFIC 270 LEA 84 MOUNTAIN 290 QUILL
See also P. -- Present data in a table.