zoukankan      html  css  js  c++  java
  • 多表查询练习之等值连接之嵌套之内连接

    等值连接:

    三张表:

      select 查询内容/结果

      from A,B,C

      where A.主键=B,主键 and C.主键=B.主键

      and 查询的条件

    两张表:

      select 查询内容/结果

      from A,B

      where A.主键=B.主键

      and 查询的条件

    sql建表请参考《sql联系表》

    案例演示:

    查询的数学的成绩

    1. 查询的结果是:成绩
    2. 查询的条件是:学生表中xm=‘张三’,课程表中kcm='数学'
    3. 用到了哪些表

    等值连接:

    select cj
    from xsb,cjb,kcb
    where xsb.xh=cjb.xh and kcb.kch=cjb.kch
    and xm='李四' and kcm='数学'
    1. 查询李四的学号
    2. 查询数学的课程号
    3. 通过学号和课程号查询成绩
    4. 合并SQL语句

    嵌套:

    select cj
    from cjb
    where xh = (select xh from xsb where xm='李四')
    and kch = (selet kch from kcb where kcm='数学');

    内连接:

    语法:

    三张表:

    select *

    from A inner join B on A.主键=B.外键

    inner join C on C.主键=B.主键

    Where 查询的条件

    两张表:

    select *

    from A inner join B on A.主键=B.主键

    where 查询的条件

    select *
    from xsb inner join cjb on xsb.xh=cjb.xh
    inner join kcb on kcb.kch=cjb.kch
    where xm='李四' and kcm='数学'

      

  • 相关阅读:
    memcached 在windows下安装及启动
    细说 ASP.NET Cache 及其高级用法
    asp.net MVC helper 和自定义函数@functions小结
    log4net 总结
    紧跟时代步伐,让我们拥抱MVC 3
    关于node-sass安装失败的解决办法
    table自适应
    获取select选中的值
    省市三级联动
    git bush 代码提交
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/13265083.html
Copyright © 2011-2022 走看看