left join;right join;inner join;where

来源:互联网 发布:axure mac安装时闪退 编辑:程序博客网 时间:2024/05/19 06:37

一道题目:

大概是一个学生的主表,和一个学生成绩的子表.

用left join;right join;inner join;where 语句查询.取结果.

 

学生信息主表:students

成绩表:score

 

区别:

 

select * from students left join score on students.id = score.sid

// 取出students表中的所有记录,在score表中如果有对应的sid则显示score表中的对应记录,否则输出null.

 

select * from students right join score on students.id = score.sid

// 取出score表中的所有记录,在students表中如果有对应的id则显示students表中的对应记录,否则输出null.

 

select * from students inner join score on students.id = score.sid

 //inner join 同 where 结果一样.只取出有对应关系的记录数.