SQL Access JOIN 多表连接使用注意
SQL Access JOIN 多表连接使用注意
1、内连接
1.1 join连接 ((可以引用别名))
1 | select a.id,b. name ,c. name from table1 a join table2 b ON a.id=s.id join table3 c on a.id=c.id |
1.2 自身连接
1 | select a.bid,a. name ,a.aid,b. name from table1 a,table1 b where a.aid=b.bid |
2、外连接
2.1.左连接Left Join 和 右连接 Right Join
1 | select table1.id, max ( name ), count (bid) from table1 left join table2 on table1.id=table2.id group by table1.id |
左连接特点:显示左边表中的所有项数据,即使其中有些项中的数据未填写完整;连接返回存在于左表而右表中却没有的行,再加上内连接的行。
右连接特点:与左连接相反。
2.2.全连接 Full Join (两边表中的内容全部显示)
1 | select field1,field2,field3 from table1 Full Join table2 on table1.id=table2.id |
3、交叉连接 Cross Join
1 | select field1+field2 from table1 Cross Join table2 |
4、其他与Ms SQL 冲突的方式
Access不支持3个表同时 连接 查询,例如:
4.1 left join:
1 | select * from table1 left join table2 on table1.field1=table2.field2 left join table3 on table1.field3=table3.field3 |
在ms sql中正常,想实现在access中使用多个表之间的连接查询,可以尝试先让两个表作连接查询形成一个视图,然后再使用形成的视图和第三个表进行连接查询,例如
1 | select * from ( select * from table1 left join table2 on table1.field1=table2.field1) as table1 left join table3 on table1.field1=table3.field1; |
4.2 inner join
1 | Select * from table1 a Inner Join table2 b On a.id = b.id Inner Join table3 c on c.id =b.id Where c.field1 = 'xx' |
Access中
1 | Select * from (table1 a Inner Join table2 b on a.id =b.id) Inner Join table3 c on c.id = b.id Where c.field1 = 'xx' |
创建时间:2022.04.28 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!
分类:
SQL 丶ACCESS
标签:
SQL
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
2021-04-28 FTP打开错误:"ftp 找不到应用程序" 的处理