create table cat
(catId int,
catName nvarchar(40))
insert into cat values(2,'White')
select *from cat
--①把cat记录distinct后的结果放入到临时表#temp中(into)
select distinct * into #temp from cat
--②把cat表的数据清空,但表没有被删除(delete)
delete from cat
--③把#temp表的数据(已经没有重复记录了),再插入到cat表中(insert和多行子查询)
insert into cat select * from #temp
--④删除临时表
drop table #temp
--讲左外连接和右外连接
--①思考题:显示公司每个员工和它上级的名字
--内连接
select w.ename,b.ename from emp w, emp b where w.mgr=b.empno
--②思考题:显示公司每个员工和它上级的名字(要求没有上级人,名字也要显示)
--左外连接:指的是左边的表的记录全部显示,如果没有匹配的记录,就用null来填。
--右外连接:指的是右边的表的记录全部显示,如果没有匹配的记录,就用null来填。
--select <字段1,字段2,...> from <表1> left/right join <表2> on <条件>
select w.ename,b.ename from emp w left join emp b on w.mgr=b.empno
1.删除重复行
删除前:
删除后:
2.左外连接的输出结果: