SQL/MX Quick Start (G06.24+, H06.03+)
HP NonStop SQL/MX Quick Start—523724-002
5-1
5
Selecting Data From More Than One
Table
This section provides information about how to join tables and use correlation names.
Joining Tables
Some queries require information from more than one table. You can select data from
two or more tables by effectively joining the tables. For example, the PARTS and
ODETAIL tables contain related data. Each table has a PARTNUM column.
PARTS Table
For part 5100, the PARTS table has this row,
PARTNUM PARTDESC PRICE QTY_AVAILABLE
------- -------------------- --------- -------------
5100 MONITOR BW, TYPE 1 150.00 3237
ODETAIL Table
For part 5100, the ODETAIL table has these rows,
ORDERNUM PARTNUM UNIT_PRICE QTY_ORDERED
-------- ------- ---------- -----------
100210 5100 150.00 10
300350 5100 150.00 12
600480 5100 135.00 60
800660 5100 150.00 5
Joined Tables
The PARTS table contains only one row with PARTNUM 5100. This row can be
combined with each of the four rows in the ODETAIL table with PARTNUM 5100 to
produce this joined table:
PARTNUM DESC PRICE QTY_AVAIL | ... PARTNUM UNIT_PRICE QTY_ORD
5100 ... ... 3237 ... 5100 ... 10
5100 ... ... 3237 ... 5100 ... 5
5100 ... ... 3237 ... 5100 ... 60
5100 ... ... 3237 ... 5100 ... 12
... ... ... ... ... ... ... ...
The PARTS table contains the number of units of each part that are available. The
ODETAIL table contains the number of units ordered for each part.