uTools-Manuals/docs/sql/LEFT JOIN 关键字.html
2019-05-07 10:15:08 +08:00

26 lines
2.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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 LEFT JOIN 关键字</h1>
<h2>SQL LEFT JOIN 关键字</h2> <p>LEFT JOIN 关键字从左表table1返回所有的行即使右表table2中没有匹配。如果右表中没有匹配则结果为 NULL。</p> <h3>SQL LEFT JOIN 语法</h3> <div class="code notranslate"><pre><code class="language-sql"><div> SELECT <em>column_name(s)</em><br/> FROM <em>table1</em><br/> LEFT JOIN <em>table2</em><br/> ON <em>table1.column_name</em>=<em>table2.column_name</em>;</div></code></pre></div> <p>或:</p> <div class="code notranslate"><pre><code class="language-sql"><div> SELECT <em>column_name(s)</em><br/> FROM <em>table1</em><br/> LEFT OUTER JOIN <em>table2</em><br/> ON <em>table1.column_name</em>=<em>table2.column_name</em>;</div></code></pre></div> <p><b>注释:</b>在某些数据库中LEFT JOIN 称为 LEFT OUTER JOIN。</p> <p style="text-align:center"><img alt="SQL LEFT JOIN" height="145" src="../image/5615cc03dc434.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 LEFT JOIN 实例</h2> <p>下面的 SQL 语句将返回所有客户及他们的订单(如果有的话):</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> SELECT Customers.CustomerName, Orders.OrderID<br/> FROM Customers<br/> LEFT JOIN Orders<br/> ON Customers.CustomerID=Orders.CustomerID<br/> ORDER BY Customers.CustomerName; </div></code></pre> </div> <p><strong>注释:</strong>LEFT JOIN 关键字从左表Customers返回所有的行即使右表Orders中没有匹配。</p> <div class="text-center padding-10 margin-t-5">
</div>
</div>