sql语句临时表删除,sql语句去重,sql语句从两个表中查询到数据放到同一个临时表输出

在这里插入图片描述
在这里插入图片描述
要求:将两个表中的Department放到一个表并去重后输出
sql语句:

if(object_id(N'tempdb..#tempTable') is not null)
	drop table #tempTable--删除临时表
select Department into #tempTable from Cfg_DepartmentGroup--创建临时表并将Cfg_DepartmentGroup表中的Department列放到临时表中

insert into #tempTable select a.Department from Cfg_Department a--将Cfg_Department表中的Department列追加到临时表中

select distinct * from #tempTable--去重输出临时表

猜你喜欢

转载自blog.csdn.net/weixin_43935474/article/details/107869485