zoukankan      html  css  js  c++  java
  • 多表查询基本语法

    //查询表中的记录数

    select count(*) from emp;

    select e.empno,e.ename,d.deptno,d.dname,d.loc from emp e,dept d where e.deptno=d.deptno;

    select e.ename,e.sal,d.dname,s.grade from emp e,dept d,salgrade s where e.deptno=d.deptno and e.sal between s.losal and s.hisal;

    

    select e.ename,e.sal,d.dname,decode(s.grade,1,'第五等工资',2,'第四等工资',3,'第三等工资') from emp e,dept d,salgrade s where e.deptno=d.deptno and e.sal between s.losal and s.hisal;

    二,左右连接

    //右连接,得到匹配结果后将右侧的结果全部显示出来

    select e.empno,e.ename,d.deptno,d.dname,d.loc from emp e,dept d where e.deptno(+)=d.deptno;

    //左连接,得到匹配结果后将左侧的结果全部显示出来

    select e.empno,e.ename,d.deptno,d.dname,d.loc from emp e,dept d where e.deptno=d.deptno(+);

    默认是左连接

    三,sql:1999语法

    交叉连接:产生笛卡尔积

    select * from emp cross join dept;

    自然连接:自动进行关联字段的匹配

    select * from emp natural join dept;

    using子句:直接关联的操作列

    select * from emp e join dept d using(deptno) where deptno=30;

    on子句:用户自己编写连接的条件

    select * from emp e join dept d on(e.deptno=d.deptno) where e.deptno=30;

    右外连接:

    select * from emp e right outer join dept d on(e.deptno=d.deptno);

    左外连接:

    select * from emp e left outer join dept d on(e.deptno=d.deptno);

  • 相关阅读:
    Struts2+Spring+Ibatis集成合并
    spring多个定时任务quartz配置
    Quartz作业调度框架
    百度搜索URL参数含义
    代理IP抓取
    解决HttpWebRequest和HtmlAgilityPack采集网页中文乱码问题
    移动端上传头像-相册、拍摄-旋转
    订单倒计时
    css flex布局 实例
    currentTarget与target
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1949465.html
Copyright © 2011-2022 走看看