当前位置:Gxlcms > 数据库问题 > 数据库表连接(内连接,外连接【左连接、右连接、全连接】交叉连接)

数据库表连接(内连接,外连接【左连接、右连接、全连接】交叉连接)

时间:2021-07-01 10:21:17 帮助过:19人阅读

* from [book] as b,[student] as where b.studentID=s.studentID

等价于

select * from [book] as b inner join [student] as s on b.studentID=s.studentID

结果为:

bookID bookname studentID studentID studentname
1 《红楼梦》 0001 0001 张飞
2 《水浒传》 0002 0002 关羽
3 《三国演义》 0003 0003 李四
4 《西游记》 0004 0004 赵敏
5 《朝花夕拾》 0005 0005 黄聪

2.左连接

select * from [book] as b left join [student] as s on b.studentID =s.studentID

结果

bookID bookname studentID studentID studentname
1 《红楼梦》 0003 0003 李四
2 《水浒传》 0005 0005 赵敏
3 《三国演义》 0003 0003 李四
4 《西游记》 0002 0002 关羽
5 《朝花夕拾》 0006 0006 黄聪
6 《西厢记》 0010 null null

3.右连接

select * from [book] as b right join [student] as s on b.studentID = s.studentID

bookID bookname studentDI studentID studentname
 null  null  null 0001 张飞
 4   《西游记》  002 0002 关羽
 3  《三国演义》  003 0003 王五
 null  null  null 0004 李四
 2  《水浒传》  005 0005 赵敏
 5  《朝花夕拾》  006 0006 黄聪

4.全连接

select * from [book] as b full out join  [student] as s on b.studentID = s.studentID

bookID bookname studentID studentID studentname
         
         
         
         
         
         

数据库表连接(内连接,外连接【左连接、右连接、全连接】交叉连接)

标签:idt   显示   红楼梦   表连接   bsp   结果   str   全连接   连接   

人气教程排行