------------------------------------------------------------------chapter3操作多个表------------------------------------------------------------------
目录:
3.1 union all 与空字符串
3.2 union 与 or
3.3 union 与 去重
3.4 组合相关的行(两个表中的字段,两种写法:join 和 from a,b表的写法)
3.5 in ,exists 和 inner join
3.6 inner join ,left join ,right join和 full join解析
3.7 外连接与过滤条件
3.8 自关联
3.9 not in, not exists 和 left join
3.10 检测两个表中的数据及对应数据的条数是否相等
3.11 聚集与内连接
彩蛋插入:日常索引的创建与检测
--创建索引 create index bill_m on qj_qp.sunneng_x_income2020(bill_month);
索引结构:create index 索引名称 on 表名(表中的某个字段)
--查询索引状态是否有效 select status,t.* from user_indexes t where table_name='QY_TMP_NEW_ADDR';
-- select * from user_ind_columns where index_name='IDX_ADDR';
--3.1union all 与 空字符串
union all 通常用于合并多个数据集,oracle中常把空字符串当做null处理
select sysdate from dual where '' is null;--2020/11/3 15:23:28
但空字符串与null并不等价
select 1 as id from dual union all select '' from dual;--ora-01790表达式必须具有与对应表达式相同的数据类型
空字符串:varchar2 类型 null:任何类型 【两者不等价】
--3.2union 与 or
当在条件中有or时,经常会改写为union
建立两个索引
create index idx_emp_empno on emp(empno);
create index idx_emp_ename on emp(ename);
select empno,ename from emp where empno=7788 or ename='SCOTT'
更改为 union all,则结果是错的(数据重复)
select empno,ename from emp where empno=7788
union all
select empno,ename from emp where e