SQL server表连接

                        表连接

1、select * from student,score ——笛卡尔积

2、两个表的连接:

法1:select student.sno, sname, degree from student,score where student.sno=score.sno ----当查询的列名两个表中都有时要在列名前面加上‘表名.’

法2:select student.sno ,sname,cno,degree from student join score   on student.sno=score.sno   

--- //inner join(默认) //left join(以左表为主表)  //right join(以右表为主表)

     

3、多个表的连接

法1:

      select student.sno, sname, cno, degree, name   

---注:select student.sno, sname, cno, degree+10, name+‘同学’ 结果是:成绩增加10分,名字后面加上同学

      from student,score,course  where student.sno=score.sno and   score.cno=course.cno

----当查询的列名不只存在1个表中都有时要在列名前面加上‘表名.’

      

法2:select student.sno, sname, cno, degree, name from student join score on student.sno=course.sn  join course on score.cno=course.cno

4、纵链接

unine

原文地址:https://www.cnblogs.com/zhulijun/p/6558421.html