SQL Access JOIN 多表连接使用注意

SQL Access JOIN 多表连接使用注意

1、内连接

1.1 join连接 ((可以引用别名))

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 自身连接

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

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 (两边表中的内容全部显示)

select field1,field2,field3 from table1 Full Join table2 on table1.id=table2.id

3、交叉连接 Cross Join

select field1+field2 from table1 Cross Join table2

4、其他与Ms SQL 冲突的方式

Access不支持3个表同时 连接 查询,例如: 

4.1  left join:

select * from table1 left join table2 on table1.field1=table2.field2 left join table3 on table1.field3=table3.field3

在ms sql中正常,想实现在access中使用多个表之间的连接查询,可以尝试先让两个表作连接查询形成一个视图,然后再使用形成的视图和第三个表进行连接查询,例如

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  

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中

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  更新时间:

posted on 2022-04-28 11:03  滔Roy  阅读(1052)  评论(0编辑  收藏  举报

导航