SQL表连接

背景


在上次的自考科目《数据库系统原理》中。已经接触到了关于数据库表连接的一些知识,近期的学习过程中又用到了关于数据库表的连接问题,趁此再跟大家一起回想一下。

导图总结


首先用一张思维导图概括一下SQL表连接的内容:



对SQL表连接有个大概的了解之后,我们通过一个小样例进一步来学习一下。首先。我建立和两张表:例如以下




外连接


外连接包含左外连接、右外连接和完整外连接。

左外连接


SQL语句:select * from table1 left join table2 on table1.id=table2.id



右外连接


SQL语句:select * from table1 right join table2 on table1.id=table2.id


完整连接


SQL语句:select * from table1 full join table2 on table1.id=table2.id



内连接


SQL语句:select table1.id,table2.score  from table1 inner join table2 on table1.id=table2.id






交叉连接


SQL语句:select *  from table1 cross join table2 on table1.id=table2.id





事实上,学习就是这样,反重复复,同一时候通过在一次次的回想过程中每次都会有不同的收获,一点点加深理解。




版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/mengfanrong/p/4802544.html