SQL表连接_sql as用法

背景

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

导图总结

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

SQL表连接1

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

SQL表连接2

外连接

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

左外连接

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

SQL表连接3

右外连接

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

SQL表连接4

完整连接

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

SQL表连接5

内连接

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

SQL表连接6

交叉连接

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

SQL表连接7

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