请问这句left join应该怎么写?

kucao 2012-01-06 03:23:32
我有三个数据表[A][B][C],他们之间的关系我分别用两段语句来描述

[A]和[B]的关系:
select a.id,b.mc from [A] as a left join
(select id,aid,mc from [B] where 查询条件) as b
on a.id=b.aid
where 查询条件
这条语句这样写没问题。

[A]和[C]的关系:
select a.id,c.lx from [A] as a, [C] as c where a.cid=c.id and 查询条件
这条语句这样写也没问题。

但是我要三个表联合后就有问题了,要[A]和[C]联合后然后left join [B],我是这样写的

select a.id,b.mc,c.lx from [A] as a, [C] as c left join
(select id,aid,mc from [B] where 查询条件) as b
on a.id=b.aid
where a.cid=c.id and 查询条件

这样写提示
Microsoft OLE DB Provider for SQL Server '80040e14'
无法绑定由多个部分组成的标识符 "a.id"。

请问这句语句我该如何来写?非常感谢。
...全文
109 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kucao 2012-01-06
  • 打赏
  • 举报
回复
非常感谢,测试了,好用!结贴!
  • 打赏
  • 举报
回复
你那样写当然不行了,楼上的可以,你试试
AcHerat 元老 2012-01-06
  • 打赏
  • 举报
回复

select a.id,b.mc,c.lx
from [A] as a join [C] as c on a.cid = c.id
left join
(select id,aid,mc from [B] where 查询条件) as b
on a.id=b.aid
where 查询条件

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧