• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

多表关联查询的问题

yycpp 2008-04-10 10:56:53
A表:id name
B表:id name
C表:idA1 idA2 idB(idA1、idA2来源于A表, idB来源于B表)
查询需得到的结果:
C.idA1 A.name(C.idA1在表A中的name) C.idA2 A.name(c.idA2在表A中的name) C.idB B.name(c.idB在表B中的name)

请问查询语句应该怎么写呢?谢谢
...全文
39 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fcuandy 2008-04-10
SELECT c.ida1,a.name,c.ida2,d.name [a.name],c.idb,b.name
FROM tc c
INNER JOIN ta a
ON c.ida1=a.id
INNER JOIN tb b
ON c.idb=b.id
INNER JOIN ta d
ON c.ida2=d.id
回复
dawugui 2008-04-10
select c.idA1,
name = (select name from A where id = C.idA1),
c.idA2,
name = (select name from A where id = C.idA2),
C.idB ,
name = (select name from B where id = C.idB)
from C
回复
xiaomeixiang 2008-04-10
A表关联两次
回复
xiaomeixiang 2008-04-10

select C.idA1,A1.name,C.idA2,A2.name,C.idB,B.name
from C , A as a1, A as a2, B
where c.idA1=a1.id and c.idA2=a2.id and c.idB=B.id
回复
suchabbs 2008-04-10
2楼和3楼都OK,哪个执行效率高点?请大牛们指点,随便帮顶+JF
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-04-10 10:56
社区公告
暂无公告