This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / SQL 的DX近来看看。我有2个表,他们的结构一样,数据有一部分是重复的。现在想把他们和并成为一张表,这个T-SQL语句该怎么写啊。
-bluej(小J);
2002-8-9
{102}
(#683739@0)
-
select * from A
union
select * from B
-yangn(Raymond);
2002-8-9
(#683749@0)
-
got it. thx. 刚刚用exists拼出来了一个。你的看起来更简单。
-bluej(小J);
2002-8-9
(#683757@0)
-
如果你想把两表中重复的数据都保留,要用union all
-cloud2001(卷云溶月);
2002-8-9
(#683775@0)
-
没有楼下几位这么复杂吧. if you want to put the results into a new table,
select * into new from A union select * from B. (but don't forget to set the db option to allow select into statement)
-yangn(Raymond);
2002-8-9
(#683776@0)
-
--delete the duplicate data first from t2
delete t2 from t1, t2 where t1.c1=t2.c1
--insert the rest data from t2 into t1
insert t1 select * from t2
-blackswan(uglyduck);
2002-8-9
(#683751@0)