sql-server – 使用select distinct插入

比方说,我有2个表t1和t2.
create table t1 
{
id int not null,col1 int null,col2 int null,col3 int null
}

create table t2
{
id uniqueidentifier not null,col3 int null
}

我想将下面的结果集插入表t2.

select distinct col1,col2,col3 from t1

如何使用查询实现此目的?我试过下面的声明,但我知道它在语法上是错误的.

insert into t2
select newid(),distinct col1,col3 from t1

解决方法

insert into t2
select newid(),a.*
from
(Select distinct col1,col3 from t1) a

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...