ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafyexjo.htm

116 lines
6.9 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="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="reference" />
<meta name="DC.Title" content="Exception join" />
<meta name="abstract" content="A left exception join returns only the rows from the first table that do not have a match in the second table." />
<meta name="description" content="A left exception join returns only the rows from the first table that do not have a match in the second table." />
<meta name="DC.subject" content="SELECT statement, EXCEPTOIN JOIN, table, EXCEPTION JOIN, examples, EXCEPTION JOIN, exception join" />
<meta name="keywords" content="SELECT statement, EXCEPTOIN JOIN, table, EXCEPTION JOIN, examples, EXCEPTION JOIN, exception join" />
<meta name="DC.Relation" scheme="URI" content="rbafyjoin.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafyexjo" />
<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>Exception join</title>
</head>
<body id="rbafyexjo"><a name="rbafyexjo"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Exception join</h1>
<div><p>A left exception join returns only the rows from the first table
that do <strong>not</strong> have a match in the second table. </p>
<div class="section"><div class="p">Using the same tables as before, return those employees that are
not responsible for any projects. <pre> <strong>SELECT</strong> EMPNO, LASTNAME, PROJNO
<strong>FROM</strong> CORPDATA.EMPLOYEE <strong>EXCEPTION JOIN</strong> CORPDATA.PROJECT
<strong>ON</strong> EMPNO = RESPEMP
<strong>WHERE</strong> LASTNAME &gt; 'S'</pre>
</div>
</div>
<div class="section"><p>This join returns the output:</p>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><thead align="left"><tr><th align="left" valign="bottom" width="33.33333333333333%" id="d0e60">EMPNO</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e62">LASTNAME</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e64">PROJNO</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000170</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">YOSHIMURA</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000180</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">SCOUTTEN</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000190</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">WALKER</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000280</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">SCHNEIDER</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000300</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">SMITH</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">000310</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">SETRIGHT</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td valign="top" width="33.33333333333333%" headers="d0e60 ">200170</td>
<td valign="top" width="33.33333333333333%" headers="d0e62 ">YAMAMOTO</td>
<td valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td valign="top" width="33.33333333333333%" headers="d0e60 ">200280</td>
<td valign="top" width="33.33333333333333%" headers="d0e62 ">SCHWARTZ</td>
<td valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td valign="top" width="33.33333333333333%" headers="d0e60 ">200310</td>
<td valign="top" width="33.33333333333333%" headers="d0e62 ">SPRINGER</td>
<td valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
<tr><td valign="top" width="33.33333333333333%" headers="d0e60 ">200330</td>
<td valign="top" width="33.33333333333333%" headers="d0e62 ">WONG</td>
<td valign="top" width="33.33333333333333%" headers="d0e64 ">-</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><div class="p">An exception join can also be written as a subquery using the
NOT EXISTS predicate. The previous query can be rewritten in the following
way: <pre> <strong>SELECT</strong> EMPNO, LASTNAME
<strong>FROM</strong> CORPDATA.EMPLOYEE
<strong>WHERE</strong> LASTNAME &gt; 'S'
<strong>AND NOT EXISTS</strong>
(<strong>SELECT</strong> * <strong>FROM</strong> CORPDATA.PROJECT
<strong>WHERE</strong> EMPNO = RESPEMP)</pre>
</div>
</div>
<div class="section"><p>The only difference in this query is that it cannot return values
from the PROJECT table.</p>
</div>
<div class="section"><p>There is a right exception join, too, that works just like a left
exception join but with the tables reversed.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyjoin.htm" title="Sometimes the information you want to see is not in a single table. To form a row of the result table, you might want to retrieve some column values from one table and some column values from another table. You can retrieve and join column values from two or more tables into a single row.">Join data from more than one table</a></div>
</div>
</div>
</body>
</html>