126 lines
7.9 KiB
HTML
126 lines
7.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="Left outer join" />
|
|
<meta name="abstract" content="A left outer join returns all the rows that an inner join returns plus one row for each of the other rows in the first table that did not have a match in the second table." />
|
|
<meta name="description" content="A left outer join returns all the rows that an inner join returns plus one row for each of the other rows in the first table that did not have a match in the second table." />
|
|
<meta name="DC.subject" content="SELECT statement, LEFT OUTER JOIN, table, examples, LEFT OUTER JOIN, left outer join, RRN scalar function" />
|
|
<meta name="keywords" content="SELECT statement, LEFT OUTER JOIN, table, examples, LEFT OUTER JOIN, left outer join, RRN scalar function" />
|
|
<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="rbafyloj" />
|
|
<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>Left outer join</title>
|
|
</head>
|
|
<body id="rbafyloj"><a name="rbafyloj"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Left outer join</h1>
|
|
<div><p>A left outer join returns all the rows that an inner join returns
|
|
plus one row for each of the other rows in the first table that did not have
|
|
a match in the second table.</p>
|
|
<div class="section"><p>Suppose you want to find all employees and the projects they are
|
|
currently responsible for. You want to see those employees that are not currently
|
|
in charge of a project as well. The following query will return a list of
|
|
all employees whose names are greater than 'S', along with their assigned
|
|
project numbers. </p>
|
|
<pre> <strong>SELECT</strong> EMPNO, LASTNAME, PROJNO
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE <strong>LEFT OUTER JOIN</strong> CORPDATA.PROJECT
|
|
<strong>ON</strong> EMPNO = RESPEMP
|
|
<strong>WHERE</strong> LASTNAME > 'S'</pre>
|
|
</div>
|
|
<div class="section"><p>The result of this query contains some employees that do not have
|
|
a project number. They are listed in the query, but have the null value returned
|
|
for their project number.</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="d0e59">EMPNO</th>
|
|
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e61">LASTNAME</th>
|
|
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e63">PROJNO</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000020</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">THOMPSON</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">PL2100</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000060</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">STERN</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">MA2110</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000100</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SPENSER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">OP2010</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000170</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">YOSHIMURA</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000180</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SCOUTTEN</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000190</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">WALKER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000250</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SMITH</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">AD3112</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000280</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SCHNEIDER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000300</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SMITH</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e59 ">000310</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e61 ">SETRIGHT</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td valign="top" width="33.33333333333333%" headers="d0e59 ">200170</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e61 ">YAMAMOTO</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td valign="top" width="33.33333333333333%" headers="d0e59 ">200280</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e61 ">SCHWARTZ</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td valign="top" width="33.33333333333333%" headers="d0e59 ">200310</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e61 ">SPRINGER</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
<tr><td valign="top" width="33.33333333333333%" headers="d0e59 ">200330</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e61 ">WONG</td>
|
|
<td valign="top" width="33.33333333333333%" headers="d0e63 ">-</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="section"> <div class="note"><span class="notetitle">Note:</span> Using the RRN scalar function to return the relative record
|
|
number for a column in the table on the right in a left outer join or exception
|
|
join will return a value of 0 for the unmatched rows.</div>
|
|
</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> |