祝愿大家身体健康!

 站点注册  找回密码
 站点注册

QQ登录

只需一步,快速开始

查看: 5195|回复: 2

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

[复制链接]

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

[复制链接]
ikana

主题

0

回帖

2

积分

新手上路

积分
2
贡献
在线时间
小时
2007-9-19 15:54:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?站点注册

×
我目前使用的是pb6.5,连接的是oracle8.0.5
假设有两个表
  table A                                 table B
      x                                         x     
    -------                                   --------
      1                                        2
      2                                        5 
      5                                        7
      6                                        9
我想得到的结果是:
             
         表C
==================================================
 A.x          B.x
 -------     ---------
  1                               
  2            2
  5            5          
  6
                7
                9
==================================================
当使用
select A.x , B.x
  from A,B
where A.x(+) = B.x(+);
时,提示:
ORA-01468:a predicate may reference only one outer-joined table
请问我应该怎么办啊?
使用A.x=B.x(+)或A.x(+)=B.x时是正常的。
[此贴子已经被作者于2007-9-19 15:56:20编辑过]
共享共进共赢Sharing And Win-win Results
SYBASEBBS - 免责申明1、欢迎访问“SYBASEBBS.COM”,本文内容及相关资源来源于网络,版权归版权方所有!本站原创内容版权归本站所有,请勿转载!
2、本文内容仅代表作者观点,不代表本站立场,作者自负,本站资源仅供学习研究,请勿非法使用,否则后果自负!请下载后24小时内删除!
3、本文内容,包括但不限于源码、文字、图片等,仅供参考。本站不对其安全性,正确性等作出保证。但本站会尽量审核会员发表的内容。
4、如本帖侵犯到任何版权问题,请立即告知本站 ,本站将及时删除并致以最深的歉意!客服邮箱:admin@sybasebbs.com
extia

主题

0

回帖

2

积分

新手上路

积分
2
贡献
在线时间
小时
2007-10-15 11:53:27 | 显示全部楼层

使用join应该可以解决了,参看

http://www.w3schools.com/sql/sql_join.asp

共享共进共赢Sharing And Win-win Results
ehxz

主题

0

回帖

59万

积分

管理员

积分
590891
贡献
在线时间
小时
2007-10-15 13:17:24 | 显示全部楼层

SQL JOIN

Joins and Keys

Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join.

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.

In the "Employees" table below, the "Employee_ID" column is the primary key, meaning that no two rows can have the same Employee_ID. The Employee_ID distinguishes two persons even if they have the same name.

When you look at the example tables below, notice that: 

  • The "Employee_ID" column is the primary key of the "Employees" table
  • The "Prod_ID" column is the primary key of the "Orders" table
  • The "Employee_ID" column in the "Orders" table is used to refer to the persons in the "Employees" table without using their names

Employees:

Employee_IDName
01Hansen, Ola
02Svendson, Tove
03Svendson, Stephen
04Pettersen, Kari

Orders:

Prod_IDProductEmployee_ID
234Printer01
657Table03
865Chair03


Referring to Two Tables

We can select data from two tables by referring to two tables, like this:

Example

Who has ordered a product, and what did they order?

SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example

Who ordered a printer?

SELECT Employees.Name
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID
AND Orders.Product='Printer'

Result

Name
Hansen, Ola


Using Joins

OR we can select data from two tables with the JOIN keyword, like this:

Example INNER JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

Who has ordered a product, and what did they order?

SELECT Employees.Name, Orders.Product
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

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 not be listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example LEFT JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

List all employees, and their orders - if any.

SELECT Employees.Name, Orders.Product
FROM Employees
LEFT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

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 also will be listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, Tove 
Svendson, StephenTable
Svendson, StephenChair
Pettersen, Kari 

Example RIGHT JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

List all orders, and who has ordered - if any.

SELECT Employees.Name, Orders.Product
FROM Employees
RIGHT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

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 also would have been listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example

Who ordered a printer?

SELECT Employees.Name
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID
WHERE Orders.Product = 'Printer'

Result

Name
Hansen, Ola

不错的样子,学习!

共享共进共赢Sharing And Win-win Results
您需要登录后才可以回帖 登录 | 站点注册

本版积分规则

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

Mail To:Admin@SybaseBbs.com

QQ|Archiver|PowerBuilder(PB)BBS社区 ( 鲁ICP备2021027222号-1 )

GMT+8, 2024-12-22 22:58 , Processed in 0.035532 second(s), 9 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表