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

80 lines
4.6 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="rzatcviewsql.htm" />
<meta name="DC.Relation" scheme="URI" content="rzatcrunscript.htm" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="viewmultsql" />
<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="viewmultsql"><a name="viewmultsql"><!-- --></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 that combines data from two or more tables
by naming more than one table in the FROM clause. In the following example
procedure, the INVENTORY_LIST table contains a column of item numbers called
ITEM_NUMBER, and a column with the cost of the item, UNIT_COST. These are
joined with the ITEM_NUMBER column and the SUPPLIER_COST column of the SUPPLIERS
table. A WHERE clause is used to limit the number of rows returned. The view
will only contain those item numbers for suppliers that can supply
an item at lower cost than the current unit cost.</div>
<ol><li class="stepexpand"><span>Use the following command to create the view:</span> <pre><strong>CREATE</strong> VIEW SAMPLECOLL.LOWER_COST AS
<strong>SELECT</strong> SUPPLIER_NUMBER, A.ITEM_NUMBER,UNIT_COST, SUPPLIER_COST
<strong>FROM</strong> SAMPLECOLL.INVENTORY_LIST A, SAMPLECOLL.SUPPLIERS B
<strong>WHERE</strong> A.ITEM_NUMBER = B.ITEM_NUMBER
<strong>AND</strong> UNIT_COST &gt; SUPPLIER_COST</pre>
</li>
<li class="stepexpand"><span>Run this statement:</span> <pre><strong>SELECT *FROM</strong> SAMPLECOLL.LOWER_COST</pre>
</li>
</ol>
<div class="section">The results look like this:<div class="p"><pre class="screen"> Display Data
Data width . . . . . . : 51
Position to line . . . . . Shift to column . . . . . .
....+....1....+....2....+....3....+....4....+....5.
SUPPLIER_NUMBER ITEM UNIT SUPPLIER_COST
NUMBER COST
1234 229740 1.50 1.00
9988 153047 10.00 8.00
2424 153047 10.00 9.00
3366 303476 2.00 1.50
3366 073956 20.00 17.00
******** End of data ********
Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split</pre>
</div>
<div class="p"><div class="note"><span class="notetitle">Note:</span> Because
no ORDER BY clause was specified for the query, the order of the rows returned
by your query may be different.</div>
</div>
<p>The rows that can be seen through
this view are only those rows that have a supplier cost that is less than
the unit cost.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzatcviewsql.htm">Create and use a view</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="rzatcrunscript.htm" title="The Run SQL Scripts window in iSeries Navigator allows you to create, edit, run, and troubleshoot scripts of SQL statements. When you have finished working with the scripts, you can save them to your PC.">Query your database using the Run SQL Scripts interface</a></div>
</div>
</div>
</body>
</html>