132 lines
7.2 KiB
HTML
132 lines
7.2 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="Cross join" />
|
||
|
<meta name="abstract" content="A cross join (or Cartesian Product join) returns a result table where each row from the first table is combined with each row from the second table." />
|
||
|
<meta name="description" content="A cross join (or Cartesian Product join) returns a result table where each row from the first table is combined with each row from the second table." />
|
||
|
<meta name="DC.subject" content="SELECT statement, CROSS JOIN, table, examples, CROSS JOIN, cross join" />
|
||
|
<meta name="keywords" content="SELECT statement, CROSS JOIN, table, examples, CROSS JOIN, cross 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="rbafycrojo" />
|
||
|
<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>Cross join</title>
|
||
|
</head>
|
||
|
<body id="rbafycrojo"><a name="rbafycrojo"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Cross join</h1>
|
||
|
<div><p>A cross join (or Cartesian Product join) returns a result table
|
||
|
where each row from the first table is combined with each row from the second
|
||
|
table.</p>
|
||
|
<div class="section"><p>The number of rows in the result table is the product of the number
|
||
|
of rows in each table. If the tables involved are large, this join can take
|
||
|
a very long time.</p>
|
||
|
</div>
|
||
|
<div class="section"><p>A cross join can be specified in two ways: using the JOIN syntax
|
||
|
or by listing the tables in the FROM clause separated by commas without using
|
||
|
a WHERE clause to supply join criteria.</p>
|
||
|
</div>
|
||
|
<div class="section"><p>Suppose the following tables exist.</p>
|
||
|
</div>
|
||
|
|
||
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. Table A</caption><thead align="left"><tr><th align="left" valign="bottom" width="50%" id="d0e44">ACOL1</th>
|
||
|
<th align="left" valign="bottom" width="50%" id="d0e46">ACOL2</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="50%" headers="d0e44 ">A1</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e46 ">AA1</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="50%" headers="d0e44 ">A2</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e46 ">AA2</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="50%" headers="d0e44 ">A3</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e46 ">AA3</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
|
||
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 2. Table B</caption><thead align="left"><tr><th align="left" valign="bottom" width="50%" id="d0e72">BCOL1</th>
|
||
|
<th align="left" valign="bottom" width="50%" id="d0e74">BCOL2</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="50%" headers="d0e72 ">B1</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e74 ">BB1</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="50%" headers="d0e72 ">B2</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e74 ">BB2</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="section"><p>The following two select statements produce identical results.
|
||
|
</p>
|
||
|
<pre> <strong>SELECT</strong> * <strong>FROM</strong> A <strong>CROSS JOIN</strong> B</pre>
|
||
|
<pre> <strong>SELECT</strong> * <strong>FROM</strong> A, B</pre>
|
||
|
</div>
|
||
|
<div class="section"><p>The result table for either of these select statements looks like
|
||
|
this:</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="25%" id="d0e120">ACOL1</th>
|
||
|
<th align="left" valign="bottom" width="25%" id="d0e122">ACOL2</th>
|
||
|
<th align="left" valign="bottom" width="25%" id="d0e124">BCOL1</th>
|
||
|
<th align="left" valign="bottom" width="25%" id="d0e126">BCOL2</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e120 ">A1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB1</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="25%" headers="d0e120 ">A1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB2</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="25%" headers="d0e120 ">A2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB1</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="25%" headers="d0e120 ">A2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB2</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="25%" headers="d0e120 ">A3</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA3</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B1</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB1</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="25%" headers="d0e120 ">A3</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e122 ">AA3</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e124 ">B2</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e126 ">BB2</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</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>
|