Join Command

You can use the JOIN primary command or the J line command to display simultaneously a row from the anchor table and related rows from the joined table. Use the J line command to select a specific row in the anchor table.

By default, a JOIN primary command operates on the first displayed row in the table at the lowest level in the display. This table becomes the anchor table for that operation. To specify the anchor table, use the JOIN command with the FROM operand and anchor table name. For example, JOIN FROM ORDERS or JOIN FROM T1. Additionally, you can designate the anchor table and row by positioning the cursor on the desired row in the anchor table.

In the following figure, the JOIN command is specified and the cursor is positioned on the row for ORDER_ID 211.

Figure: JOIN Command

--------------------- Archive Browse: FOPDEMO.ARCHIVE.FILE --------------------
Command ===> JOIN                                             Scroll ===> PAGE 

Cmd F == Table: FOPDEMO.ORDERS(T1) ========================= 1 OF 19 === MORE>>
      ORDER_ID CUST_ID ORDER_DATE ORDER_TIME FREIGHT_CHARGES ORDER_SALESMAN 
      -------- ------- ---------- ---------- --------------- -------------- 
*** *********************************** TOP ***********************************
___       205   00192  1997-05-24  12.12.51       48.52          NE012 
___       205   00192  1997-02-24  12.12.51       48.52          NE012 
___       206   00093  1997-02-24  12.12.51       48.52          SW012 
___       207   00067  1997-02-24  12.12.51       48.52          WE012 
___       208   03189  1997-02-24  12.12.51       48.52          NW012 
___       209   00143  1997-02-24  12.12.51       48.52          SW012 
___       210   00239  1997-02-24  12.12.51       48.52          NW012 
|__       211   00284  1997-02-24  12.12.51       48.52          SC012 
___       212   00327  1997-02-24  12.12.51       48.52          SC012 
___       213   00371  1997-02-24  12.12.51       48.52          NE012 
___       214   00415  1997-02-24  12.12.51       48.52          NC012 
___       215   02221  1997-02-24  12.12.51       48.52          SE012 
___       216   00019  1997-02-24  12.12.51       48.52          SC012 
___       217   00110  1997-02-24  12.12.51       48.52          SE012 
___       288   00131  1997-02-24  12.12.51       48.52          SW012 
___       333   01210  1997-02-24  12.12.51       48.52          SE012 
___       417   00448  1997-02-24  12.12.51       48.52          SE012 
___       727   00420  1997-02-24  12.12.51       48.52          NE012 

Press ENTER to execute the JOIN command. If only one table in the Access Definition or the file is directly related to the anchor table, any related rows from that table are displayed automatically. If the anchor table has no related tables, a message indicates the command cannot be satisfied. See No Related Tables for more information.

Join Using DB2® LIKE Syntax

You can use DB2 LIKE syntax to display a selection list of tables to join at any level. For example, to find tables with names beginning with “D” that are related to the ORDERS table, specify:

JOIN D% FROM ORDERS

If several tables with names that begin with “D” are directly related to ORDERS, they are included in a selection list. You can select one or more listed tables. If only one table meets the criteria, it is joined and displayed without displaying a selection list.

To minimize typing, you can use the level indicator to specify the anchor table for the FROM operand. For example, the ORDERS table in Figure 1 is assigned the level T1. You can specify the JOIN command as:

JOIN D% FROM T1