– 备份表
– where 1!=1 加这个 备份表只有表结构没有表记录
– where 1=1 备份表即有表结构又有表记录
create table enmp_bf1 as select * from emp where 1!=1; – 复制
合并结果集
select * from enmp_bf
union
select * from emp;
– 32 重复 所有列的内容都一样
– union all 包含重复记录 union 去重复记录
– emp dept 避免笛卡尔集 通过关联条件
– emp 50 dept 1 内连接查询的内容 都是符合条件的记录
– 外连接
select * from emp p inner join dept d on p.deptno=d.deptno;
– t_student t_class
select * from t_student s inner join t_class c on s.classid =c.cid;
– inner join(标准版) 和 , 都属于内连接
– 外连接 和内连接的区别
– 内连接 都是符合条件的记录
– 外连接 存在不符合条件的可能
– 左外连接 以左表为基准 左表有的都显示 右表没有以null来填
select * from dept d LEFT JOIN emp p on p.deptno=d.deptno;
– 右链接
select * from emp p right JOIN dept d on p.deptno=d.deptno;
– 自然链接 不需要加额外的链接条件 会自动匹配
select * from dept NATURAL join emp;