• select 多表查询


    连接查询实际上是通过各个表之间共同列的关联性来查询数据的,它是关系数据库查询最主要的特征. 

    select 表1.字段名1,表2.字段名2,... 
    from 表1,表2 
    where 连接条件

    连接查询分类: 
    1.自连接查询,对同一个表进行连接操作 
    2.内连接查询,<又分为:自然连接、等值连接、不等值连接三种> 
    3.外连接查询,<又分为:左外连接、右外连接、全外连接三种> 
    4.交叉连接查询,也作无条件查询。 
    5.联合查询

    一、自连接查询: 
          
            一个表自己与自己建立连接称为自连接或自身连接。进行自连接就如同两个分开的表一样,可以把一个表的某一行与同一表中的另一行连接起来。 
    例: 
    查询选学“101”课程的成绩高于“9505201”号学生成绩的所有学生记录, 
    并按成绩从高到低排列。 
    select x.* from sclass x,sclass y 
    where x.cno=''101'' and x.degree>y.degree and y.sno=''9505201'' and y.cno=''101'' 
    order by x.degree desc 

    select  from (select degree from sclass where con='101')a, (select degree from sclass where con="101" and sno='9505201')b

    where a.degree > b.degree

    1、查询“001”课程比“002”课程成绩高的所有学生的学号;-》 查询 (同)一个学生的001课程 比 他的002 课程的成绩高。
      select a.S# from (select s#,score from SC where C#=’001′) a,(select s#,score
      from SC where C#=’002′) b
      where a.score>b.score and a.s#=b.s#;

    select  a.S# from SC a, SC b

    where a.C#='001' and b.C#='002' and a.S#=b.S# and a.score > b.score

    http://www.tuicool.com/articles/26NZry

  • 相关阅读:
    【C++日常】C++动态命名变量名
    两个整数相除
    Jsp页面跳转 接收时的乱码问题
    Reverse a singly linked list
    Java处理excel文件
    Navicat for mysql 破解
    EasyUi 分页 和 表格数据加载
    Spring 框架下Controller 返回结果在EasyUI显示
    svn ubuntu command(转载)
    Shiro Security
  • 原文地址:https://www.cnblogs.com/ydxblog/p/5773104.html
Copyright © 2020-2023  润新知