ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatc_5.4.0.1/rzatcmulttables.htm

117 lines
7.0 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2005" />
<meta name="DC.rights.owner" content="(C) Copyright IBM Corporation 2005" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="task" />
<meta name="DC.Title" content="Create a view combining data from multiple tables" />
<meta name="DC.Relation" scheme="URI" content="rzatcview.htm" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzatcmulttables" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Create a view combining data from multiple tables</title>
</head>
<body id="rzatcmulttables"><a name="rzatcmulttables"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Create a view combining data from multiple tables</h1>
<div><div class="section">You can create a view combining information from more than one table
by selecting more than one table in the work area of the New View window.
You can create a simple view from more than one table by selecting the columns
that you want to include from different tables and clicking <strong>OK</strong>. However,
this example shows how to create a view that joins information from two different
tables and returns only those rows that you want to see, much like using a
WHERE clause. <p>In this example, you create a view that contains only those
item numbers for suppliers that can supply an item at lower cost than the
current unit cost. This requires selecting ITEM_NUMBER and UNIT_COST
from the INVENTORY_LIST table and joining them with SUPPLIER_NUMBER and SUPPLIER_COST
from the SUPPLIERS table. A WHERE clause is used to limit the number of rows
returned.</p>
</div>
<div class="p"><span>To create a view called LOWER_COST:</span><ol type="a"><li><span>Navigate to schema LIBRARY1. Right-click <span class="uicontrol">Views</span> and
select <span class="uicontrol">New</span>.</span></li>
<li><span>Select INVENTORY_LIST from SAMPLELIB and SUPPLIERS from LIBRARY1. </span></li>
<li><span>Click <span class="uicontrol">OK</span>. Both tables should appear in
the working area of the window.</span></li>
<li><span>Select ITEM_NUMBER and UNIT_COST from INVENTORY_LIST.</span></li>
<li><span>Select SUPPLIER_NUMBER and SUPPLIER_COST from SUPPLIERS.</span></li>
<li><span>To define the join, select ITEM_NUMBER from INVENTORY_LIST and
drag it to ITEM_NUMBER in SUPPLIERS. A line is drawn from one column to the
other and the Join window opens.</span></li>
<li><span>On the Join window, select <span class="uicontrol">Return rows with a matching
condition (Inner Join)</span>.</span></li>
<li><span>Click <span class="uicontrol">OK</span>.</span></li>
<li><span>Click <span class="uicontrol">Select Rows</span> to create a WHERE clause
for the view. Double-click LIBRARY1.SUPPLIERS.SUPPLIER_COST, then double-click
the <span class="uicontrol">&lt;</span> operator and finally double-click SAMPLELIB.INVENTORY_LIST.UNIT_COST
. As you click the items, they appear in the window. You can also type this
in directly.</span></li>
<li><span>Click <span class="uicontrol">OK</span> to create the view, LOWER_COST.</span></li>
</ol>
<p><br /><img src="rzatc007.gif" alt="screen capture of new library window" /><br /></p>
</div>
<div class="section"><div class="note"><span class="notetitle">Note:</span> You can view the SQL used to create this view by selecting <span class="uicontrol">Show
SQL</span>. You can also edit the SQL by selecting <span class="uicontrol">Edit SQL</span>.
Edit SQL starts Run SQL Scripts, where you can edit your SQL statement. Be
aware, however, that if you change the SQL, you will need to run the statement
from Run SQL Scripts rather than returning to the New View window. If you
return to the New View window, your changes are not saved.</div>
<p>To display
the contents of this new view, right-click LOWER_COST and select <span class="uicontrol">View
Contents</span>. The rows that you see through this view are only those
rows that have a supplier cost that is less than the unit cost.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="border" border="1" rules="all"><thead align="left"><tr><th valign="top" width="27.247956403269757%" id="d0e98">ITEM_NUMBER </th>
<th valign="top" width="20.435967302452315%" id="d0e100">UNIT_COST </th>
<th valign="top" width="27.79291553133515%" id="d0e102">SUPPLIER_NUMBER </th>
<th valign="top" width="24.52316076294278%" id="d0e104">SUPPLIER_COST</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="27.247956403269757%" headers="d0e98 ">153047 </td>
<td valign="top" width="20.435967302452315%" headers="d0e100 ">10.00</td>
<td valign="top" width="27.79291553133515%" headers="d0e102 ">9988 </td>
<td valign="top" width="24.52316076294278%" headers="d0e104 ">8.00</td>
</tr>
<tr><td valign="top" width="27.247956403269757%" headers="d0e98 ">153047</td>
<td valign="top" width="20.435967302452315%" headers="d0e100 ">10.00</td>
<td valign="top" width="27.79291553133515%" headers="d0e102 ">2424 </td>
<td valign="top" width="24.52316076294278%" headers="d0e104 ">9.00</td>
</tr>
<tr><td valign="top" width="27.247956403269757%" headers="d0e98 ">229740</td>
<td valign="top" width="20.435967302452315%" headers="d0e100 ">1.50</td>
<td valign="top" width="27.79291553133515%" headers="d0e102 ">1234 </td>
<td valign="top" width="24.52316076294278%" headers="d0e104 ">1.00</td>
</tr>
<tr><td valign="top" width="27.247956403269757%" headers="d0e98 ">303476</td>
<td valign="top" width="20.435967302452315%" headers="d0e100 ">2.00</td>
<td valign="top" width="27.79291553133515%" headers="d0e102 ">3366 </td>
<td valign="top" width="24.52316076294278%" headers="d0e104 ">1.50 </td>
</tr>
<tr><td valign="top" width="27.247956403269757%" headers="d0e98 ">073956 </td>
<td valign="top" width="20.435967302452315%" headers="d0e100 ">20.00</td>
<td valign="top" width="27.79291553133515%" headers="d0e102 ">3366</td>
<td valign="top" width="24.52316076294278%" headers="d0e104 ">17.00</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzatcview.htm">Create and use a view</a></div>
</div>
</div>
</body>
</html>