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

87 lines
5.3 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="Inner join using JOIN syntax" />
<meta name="abstract" content="To use the inner join syntax, both of the tables you are joining are listed in the FROM clause, along with the join condition that applies to the tables." />
<meta name="description" content="To use the inner join syntax, both of the tables you are joining are listed in the FROM clause, along with the join condition that applies to the tables." />
<meta name="DC.subject" content="SELECT statement, INNER JOIN, table, examples, INNER JOIN" />
<meta name="keywords" content="SELECT statement, INNER JOIN, table, examples, INNER JOIN" />
<meta name="DC.Relation" scheme="URI" content="rbafyinj.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="rbafyinsyn" />
<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>Inner join using JOIN syntax</title>
</head>
<body id="rbafyinsyn"><a name="rbafyinsyn"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Inner join using JOIN syntax</h1>
<div><p>To use the inner join syntax, both of the tables you are joining
are listed in the FROM clause, along with the join condition that applies
to the tables.</p>
<div class="section"><p>The join condition is specified after the ON keyword and determines
how the two tables are to be compared to each other to produce the join result.
The condition can be any comparison operator; it does not need to be the equal
operator. Multiple join conditions can be specified in the ON clause separated
by the AND keyword. Any additional conditions that do not relate to the actual
join are specified in either the WHERE clause or as part of the actual join
in the ON clause. </p>
<pre> <strong>SELECT</strong> EMPNO, LASTNAME, PROJNO
<strong>FROM</strong> CORPDATA.EMPLOYEE <strong>INNER JOIN</strong> CORPDATA.PROJECT
<strong>ON</strong> EMPNO = RESPEMP
<strong>WHERE</strong> LASTNAME &gt; 'S'</pre>
</div>
<div class="section"><p>In this example, the join is done on the two tables using the
EMPNO and RESPEMP columns from the tables. Since only employees that have
last names starting with at least 'S' are to be returned, this additional
condition is provided in the WHERE clause.</p>
</div>
<div class="section"><p>This query returns the following 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="d0e58">EMPNO</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e60">LASTNAME</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e62">PROJNO</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e58 ">000250</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">SMITH</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">AD3112</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e58 ">000060</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">STERN</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">MA2110</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e58 ">000100</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">SPENSER</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">OP2010</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e58 ">000020</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e60 ">THOMPSON</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e62 ">PL2100</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyinj.htm" title="An inner join returns only the rows from each table that have matching values in the join columns. Any rows that do not have a match between the tables will not appear in the result table.">Inner join</a></div>
</div>
</div>
</body>
</html>