ikana 发表于 2007-9-19 15:54:47

[求助]请问在pb6.5中如何使用全连接?

我目前使用的是pb6.5,连接的是oracle8.0.5<br/>假设有两个表<br/>&nbsp; table A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table B<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; -------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------- <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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bsp;&nbsp;&nbsp; 表C<br/>==================================================<br/>&nbsp;A.x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B.x<br/>&nbsp;-------&nbsp;&nbsp;&nbsp;&nbsp; ---------<br/>&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br/>&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp; 6 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9<br/>==================================================<br/>当使用<br/>select A.x , B.x <br/>&nbsp; from A,B<br/>where A.x(+) = B.x(+);<br/>时,提示:<br/>ORA-01468:a predicate may reference only one outer-joined table<br/>请问我应该怎么办啊?<br/>使用A.x=B.x(+)或A.x(+)=B.x时是正常的。<br/>
[此贴子已经被作者于2007-9-19 15:56:20编辑过]

extia 发表于 2007-10-15 11:53:27

<p>使用join应该可以解决了,参看</p><p><a href="http://www.w3schools.com/sql/sql_join.asp">http://www.w3schools.com/sql/sql_join.asp</a></p>

ehxz 发表于 2007-10-15 13:17:24

SQL JOIN

<strong><h2>Joins and Keys </h2><p>Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join. </p><p>Tables in a database can be related to each other with keys. A primary key is a column with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table. </p><p>In the "Employees" table below, the "Employee_ID" column is the primary key, meaning that <b>no</b> two rows can have the same Employee_ID. The Employee_ID distinguishes two persons even if they have the same name. </p><p>When you look at the example tables below, notice that:&nbsp; </p><ul><li>The "Employee_ID" column is the primary key of the "Employees" table </li><li>The "Prod_ID" column is the primary key of the "Orders" table </li><li>The "Employee_ID" column in the "Orders" table is used to refer to the persons in the "Employees" table without using their names </li></ul><hr/><p><b>Employees</b>:</p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="25%">Employee_ID</th><th align="left" width="35%">Name</th></tr><tr><td>01</td><td>Hansen, Ola</td></tr><tr><td>02</td><td>Svendson, Tove</td></tr><tr><td>03</td><td>Svendson, Stephen</td></tr><tr><td>04</td><td>Pettersen, Kari</td></tr></tbody></table></p><p><b>Orders:</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="15%">Prod_ID</th><th align="left" width="20%">Product</th><th align="left" width="25%">Employee_ID</th></tr><tr><td>234</td><td>Printer</td><td>01</td></tr><tr><td>657</td><td>Table</td><td>03</td></tr><tr><td>865</td><td>Chair</td><td>03</td></tr></tbody></table><br/></p><hr/><h2>Referring to Two Tables</h2><p>We can select data from two tables by referring to two tables, like this:</p><h3>Example</h3><p>Who has ordered a product, and what did they order?</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID</pre></td></tr></tbody></table></p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="35%"><b>Name</b></th><th align="left" width="25%">Product</th></tr><tr><td>Hansen, Ola</td><td>Printer</td></tr><tr><td>Svendson, Stephen</td><td>Table</td></tr><tr><td>Svendson, Stephen</td><td>Chair</td></tr></tbody></table></p><h3>Example</h3><p>Who ordered a printer?</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID
AND Orders.Product='Printer'</pre></td></tr></tbody></table></p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left"><b>Name</b></th></tr><tr><td>Hansen, Ola</td></tr></tbody></table><br/></p><hr/><h2>Using Joins</h2><p>OR we can select data from two tables with the JOIN keyword, like this:</p><h3>Example INNER JOIN</h3><p><b>Syntax</b></p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield</pre></td></tr></tbody></table></p><p>Who has ordered a product, and what did they order?</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name, Orders.Product
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID</pre></td></tr></tbody></table></p><p>The INNER JOIN returns all rows from both tables where there is a match. If there are rows in Employees that do not have matches in Orders, those rows will <b>not</b> be listed.</p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="35%"><b>Name</b></th><th align="left" width="25%">Product</th></tr><tr><td>Hansen, Ola</td><td>Printer</td></tr><tr><td>Svendson, Stephen</td><td>Table</td></tr><tr><td>Svendson, Stephen</td><td>Chair</td></tr></tbody></table></p><h3>Example LEFT JOIN</h3><p><b>Syntax</b></p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT field1, field2, field3
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield</pre></td></tr></tbody></table></p><p>List all employees, and their orders - if any.</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name, Orders.Product
FROM Employees
LEFT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID</pre></td></tr></tbody></table></p><p>The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows <b>also</b> will be listed.</p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="35%"><b>Name</b></th><th align="left" width="25%">Product</th></tr><tr><td>Hansen, Ola</td><td>Printer</td></tr><tr><td>Svendson, Tove</td><td>&nbsp;</td></tr><tr><td>Svendson, Stephen</td><td>Table</td></tr><tr><td>Svendson, Stephen</td><td>Chair</td></tr><tr><td>Pettersen, Kari</td><td>&nbsp;</td></tr></tbody></table></p><h3>Example RIGHT JOIN</h3><p><b>Syntax</b></p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield</pre></td></tr></tbody></table></p><p>List all orders, and who has ordered - if any.</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name, Orders.Product
FROM Employees
RIGHT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID</pre></td></tr></tbody></table></p><p>The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees). If there had been any rows in Orders that did not have matches in Employees, those rows <b>also</b> would have been listed.</p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left" width="35%"><b>Name</b></th><th align="left" width="25%">Product</th></tr><tr><td>Hansen, Ola</td><td>Printer</td></tr><tr><td>Svendson, Stephen</td><td>Table</td></tr><tr><td>Svendson, Stephen</td><td>Chair</td></tr></tbody></table></p><h3>Example</h3><p>Who ordered a printer?</p><p><table class="ex" cellspacing="0" width="100%" border="1"><tbody><tr><td><pre>SELECT Employees.Name
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID
WHERE Orders.Product = 'Printer'</pre></td></tr></tbody></table></p><p><b>Result</b></p><p><table class="ex" cellspacing="0" width="60%" border="1"><tbody><tr><th align="left"><b>Name</b></th></tr><tr><td>Hansen, Ola</td></tr></tbody></table></p><p></p><p>不错的样子,学习!</p></strong>
页: [1]
查看完整版本: [求助]请问在pb6.5中如何使用全连接?

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com