uTools-Manuals/docs/sql/FULL OUTER JOIN 关键字.html
2019-04-21 11:50:48 +08:00

40 lines
3.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="m-bg">
<h1>SQL FULL OUTER JOIN 关键字</h1>
<h2>SQL FULL OUTER JOIN 关键字</h2> <p>FULL OUTER JOIN 关键字只要左表table1和右表table2其中一个表中存在匹配则返回行.</p> <p>FULL OUTER JOIN 关键字结合了 LEFT JOIN 和 RIGHT JOIN 的结果。</p> <h3>SQL FULL OUTER JOIN 语法</h3> <div class="code notranslate"><pre><div> SELECT <em>column_name(s)</em><br/> FROM <em>table1</em><br/> FULL OUTER JOIN <em>table2</em><br/> ON <em>table1.column_name</em>=<em>table2.column_name</em>;</div></pre></div> <p style="text-align:center"><img alt="SQL FULL OUTER JOIN" height="145" src="../image/5615cc0fd9031.gif" width="200"/></p> <h2>演示数据库</h2> <p>在本教程中,我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "Customers" 表的数据:</p> <table class="reference notranslate">
<tr>
<th width="15%">CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>1<br/><br/>
</td> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Obere Str. 57</td> <td>Berlin</td> <td>12209</td> <td>Germany</td> </tr>
<tr>
<td>2</td> <td>Ana Trujillo Emparedados y helados</td> <td>Ana Trujillo</td> <td>Avda. de la Constitución 2222</td> <td>México D.F.</td> <td>05021</td> <td>Mexico</td> </tr>
<tr>
<td>3</td> <td>Antonio Moreno Taquería</td> <td>Antonio Moreno</td> <td>Mataderos 2312</td> <td>México D.F.</td> <td>05023</td> <td>Mexico</td> </tr>
</table>
<p>选自 "Orders" 表的数据:</p> <table class="reference notranslate">
<tr>
<th width="15%">OrderID</th> <th>CustomerID</th> <th>EmployeeID</th> <th>OrderDate</th> <th>ShipperID</th> </tr>
<tr>
<td>10308</td> <td>2</td> <td>7</td> <td>1996-09-18</td> <td>3</td> </tr>
<tr>
<td>10309</td> <td>37</td> <td>3</td> <td>1996-09-19</td> <td>1</td> </tr>
<tr>
<td>10310</td> <td>77</td> <td>8</td> <td>1996-09-20</td> <td>2</td> </tr>
</table>
<h2>SQL FULL OUTER JOIN 实例</h2> <p>下面的 SQL 语句选取所有的客户及所有的订单:</p> <div class="code notranslate"><pre><div> SELECT Customers.CustomerName, Orders.OrderID<br/> FROM Customers<br/> FULL OUTER JOIN Orders<br/> ON Customers.CustomerID=Orders.CustomerID<br/> ORDER BY Customers.CustomerName; </div></pre></div> <p>选自结果集中的数据如下所示:</p> <table class="reference notranslate">
<tr>
<th>CustomerName</th> <th>OrderID</th> </tr>
<tr>
<td>Alfreds Futterkiste</td> <td> </td> </tr>
<tr>
<td>Ana Trujillo Emparedados y helados </td> <td>10308</td> </tr>
<tr>
<td>Antonio Moreno Taquería </td> <td>10365</td> </tr>
<tr>
<td> </td> <td>10382</td> </tr>
<tr>
<td> </td> <td>10351</td> </tr>
</table>
<p><strong>注释:</strong>FULL OUTER JOIN 关键字返回左表Customers和右表Orders中所有的行。如果 "Customers" 表中的行在 "Orders" 中没有匹配或者 "Orders" 表中的行在 "Customers" 表中没有匹配,也会列出这些行。</p> <div class="text-center padding-10 margin-t-5">
</div>
</div>