1 连接查询 :
1) 把两张表连成一张表
select * from student(第一张表名) t1(随便起的名) join score(第二张表名) t2(随便起的名) on t1.son=t2.son ( son是两张表相同的项目名称)
查询两张表里不同的项目:
select t1. sno(第一张表里的内容) ,t2 . degree(第二张表里的内容) from student t1 join score t2 on t1 . son =t2 . son
2) 把三张表连成一张表:
第一张和第二张表连一起:
select * from student t1 join score t2 on t1 . son = t2 . son
第二张表和第三张表连一起
join course t3 on t2 . cno = t3 . cno
查询 :
select t1. sname (第一张表里的内容) ,t2 . degree ,t3.cname(第二张表里的内容) from student t1
join score t2 on t1 . son =t2 . son
join course t3 on t2 . cno = t3 . cno
order by t1.sname ( 第一张表里的sname 里的内容相同的放一块 )
左键关键:
select t1. sno , t2 . degree from student t1
left join score t2 on t1 . son = t2 . son
右键关键
select t1. sno , t2 . degree from student t1
right join score t2 on t1 . son = t2 . son
查询两张表所有的内容:
select * from student t1
right join score t2 on 1=1