left join,rignt join,inner join的区分

来源:互联网 发布:淘宝用卷怎么用 编辑:程序博客网 时间:2024/05/16 12:05

外链接:

left join(left outer join):左外连接(匹配左表所有行,如果左表的某行在右表没有匹配行,则在相关联的右表要查询的列用空值代替)

right join (right outer join) : 右外连接(匹配右表所有行,如果右表的某行在左表没有匹配行,则在相关联的左表要查询的列用空值代替)

内连接:

inner join:内连接(左右表匹配ID行)

如:学生表和成绩表

Student                

id       name     

001      a       

002      b        

Score

id    scores

001    80

003    90

左外连接:

select  *  from Student stu  left join Score sco on stu.id=sco.id

id     name   id    scores

001   a        001    80

002   b  

右外链接:              

select * from Student stu  right join Score sco on stu.id=sco.id

id     name   id    scores

001   a        001    80

                   003    90

内连接:

select * from Student (as) stu  inner join Score (as) sco on stu.id=sco.id

select * fromStudent (as) stu,Score (as) sco   where stu.id=sco.id --另一种写法

id     name   id    scores

001   a        001    80


0 0
原创粉丝点击