access 表中关联表查询问题

cooling 2004-04-20 09:24:56
table1

字段 id theme FileId MemoId
数据 1 x1 1 2
数据 2 x2 3 0


table2

字段 id style info
数据 1 file info1
数据 2 memo info2
数据 3 file info3

想要查询后显示下面信息

table1.id table1.theme table2.info table2.info
1 x1 info1 info2
2 x2 info3 (空)

我现在sql语句是这么写的:
select
a.id, a.theme, b.info, c.info
form
table1 a left join table2 b on a.fileid = b.id
left join
table2 c on a.memoid = c.id

但有问题。该怎么写呢?
...全文
54 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooling 2004-04-23
  • 打赏
  • 举报
回复


还是写不出来。

如果照 amtyuranus(升星中。。。) 的写,那 d 表中不是有两个 info 了吗?该怎么区分呢??



请大家帮忙呀。
amtyuranus 2004-04-20
  • 打赏
  • 举报
回复
先把前面三个字段生成好了,然后做为一个表再left join 第二张表

select d.id,d.theme ..... from (select
a.id, a.theme, b.info, c.info
form
table1 a left join table2 b on a.fileid = b.id) as d left join .....

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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