sybase有多个left join 和多个union会报错

本文解决了一个在使用ANSI SQL语法时遇到的Sybase数据库错误,具体错误信息为AdaptiveServer无法执行请求的操作,因为列'organId'不在连接表达式的范围内。通过调整查询语句结构,将外联接操作分解,避免了使用内部包含UNION的衍生表,从而解决了问题。最后,作者创建了一个视图来替代原始的查询结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错内容:

Adaptive Server cannot perform the requested action because column

'organId' is not within the scope of the joined table expression.Check

your command for missing or incorrect database objects,variable names,

and/or input data.


select ...

from

t1

left join

t2

on t1=t2

left join

(

select ... from t3

union all

select ... from t4

)t5

on t1=t5

这样写会报错。

原因 :Hi, it was a limatation of Sybase in the end when using ANSI sql or at least thats what the DBA's told me. A derived table is seen as an inline view in the SQL BO generates, Sybase can handle that but if the inline view contains a union (so your derived table has a union) and there are 3 or more other tables joined with the SQL it throws this error, works fine if only two tables, or if you break the union up into two derived tables. In the end I created the view on the db. I find Sybase frustrating no decode no MINUS commands icon_neutral.gif 

Thanks

(出自:http://www.forumtopics.com/busobj/viewtopic.php?p=442226)

解决方法:t1和t2联合,t1和t5联合,t5是一个union这样会报错。把t1和t2先联合之后在于t5联合

select t1.* from

(select ...

from

t1

left join

t2

on ...

) t6

left join

(

select ... from t3

union all

select ... from t4

)t5

on t6=t5


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值