数据库的连接查询比较

select * from Table1 join_type Table2 on join_condition

说明:join_type是连接类型,join_condition是关联条件

inner join:显示Table1和Table2中通过Relation建立关联的信息,多余的信息不显示。

left join:显示Table1和Table2中通过Relation建立关联的信息,并同时显示左表中所有信息

right join:Table1和Table2中通过Relation建立关联的信息,并同时显示右表中所有信息

实例:

表一:学生表

表二:课程表

表三:分数表

下面的连接查询可以区别这三种连接:

use DbJoin go select * from T_Student inner join T_Score on T_Student.S_ID=T_Score.S_ID

use DbJoin go select * from T_Student left join T_Score on T_Student.S_ID=T_Score.S_ID

use DbJoin go select * from T_Student right join T_Score on T_Student.S_ID=T_Score.S_ID

原文地址:https://www.cnblogs.com/jsping/p/2517142.html