• SQL server 数据库——表连接(多表横向连接,纵向连接)


                            表连接

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

    2、两个表的连接:

    法1:select student.sno, sname, degree

            from student,score  ----当查询的列名两个表中都有时要在列名前面加上‘表名.’

            where student.sno=score.sno

    法2:select cno, (select sname from student where student.sno=score.sno),degree from score

    法3:select student.sno ,sname,cno,degree

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

           on student.sno=score.sno

    3、三个表的连接

    法1:

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

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

           where student.sno=score.sno

           and   score.cno=course.cno

    法2:select student.sno, sname, cno, degree, name

           from student join score

          on student.sno=course.sno

              join course

         on score.cno=course.cno

    4、纵链接

          

  • 相关阅读:
    新的学期,新的学习
    织梦最新
    selectd选项跳转链接
    字体统一大小
    js点击后进入到另一个页面的TAB选项中
    织梦套后台
    js获取距离各边的距离
    将时间的秒数转化为分钟数
    jquery手写tab选项卡功能
    js中的定时器
  • 原文地址:https://www.cnblogs.com/weiyu11/p/6543820.html
Copyright © 2020-2023  润新知