搜索并消除2个表

时间:2017-09-11 15:56:58

标签: sql-server database fill migrate sql-manager

我是SQL的新手,并尝试基于两个表创建一个表。 我有两个表,每列有7列,有些寄存器有不完整的信息,但我需要过滤这个。

条件。 - 结果表上的ID_1上没有重复项。 "容易我认为使用不同,我有非重复" - ID不能重复1-2。但如果我有一个我需要复制包含更多信息的行。

我会附上有关任务和我的新手代码的信息

    create database Task23

    go

    USE Task23

    create table table_entities
(
entityID_1 varchar(max),
entityID_2 varchar(max),
dateAdded varchar(max),
entityName varchar(max),
entityWebsite varchar(max),
entityIndustry varchar(max),
entityCountry varchar(max),
)

create table table_entities_NEW
(

entityID_1 varchar(max),
entityID_2 varchar(max),
dateAdded varchar(max),
entityName varchar(max),
entityWebsite varchar(max),
entityIndustry varchar(max),
entityCountry varchar(max),
)

create table table_entities_RESULT
(

entityID_1 varchar(max),
entityID_2 varchar(max),
dateAdded varchar(max),
entityName varchar(max),
entityWebsite varchar(max),
entityIndustry varchar(max),
entityCountry varchar(max),
)

go
create table table_entities_full
(

entityID_1 varchar(max),
entityID_2 varchar(max),
dateAdded varchar(max),
entityName varchar(max),
entityWebsite varchar(max),
entityIndustry varchar(max),
entityCountry varchar(max),
)
go



insert into table_entities values ('e113942','processndata','1504167890','Process and Data','http://yadawebsite.com','Industrial Automation','USA');
insert into table_entities values ('collectivedata' ,'', '1504165693' , 'Collective Data' , 'http://www.collectivedata.com' , 'IT' , 'USA');
insert into table_entities values ('bloodsense','e109984','1504165620','BloodSense','http://just asample.com','Medical Devices','USA');
insert into table_entities values ('e117385','','','TrendHealth Ltd','','Healthcare','');
insert into table_entities values ('mando','','','Mando Health','','Healthcare','');

go


insert into table_entities_NEW values ('e117385','trendhealth','1504167890','TrendHealth Ltd','http://samplewebsite.com','Healthcare','UK');
insert into table_entities_NEW values ('trendhealth' ,'', '' , 'TrendHealth Ltd' , '' , '' , 'UK');
insert into table_entities_NEW values ('mando','e93344','1504117360','Long View Med','http://just asample.com','Healthcare','USA');
insert into table_entities_NEW values ('e112481','','','Long View Med','','Medical Devices','');
insert into table_entities_NEW values ('e112481','','','Long View Med','','Medical Devices','');
insert into table_entities_NEW values ('trendhealth','','','TrendHealth Ltd','','','');
insert into table_entities_NEW values ('microsense','','','MicroSense LLC','','','USA');
insert into table_entities_NEW values ('e114958','','','Telemed','','Medical Devices','');




select * from table_entities;
select * from table_entities_NEW;
select * from table_entities_RESULT;


insert into table_entities_RESULT select distinct * from table_entities
insert into table_entities_RESULT select distinct * from table_entities_new

这就是我插入时的第一个问题我有一个副本,因为比较文件中的所有寄存器并且不像我希望的那样填充。

点击here

预期输出为:

insert into table_entities_RESULT values ('e113942','processndata','1504167890','Process and Data','http://yadawebsite.com','Industrial Automation','USA');
insert into table_entities_RESULT values ('collectivedata' ,'', '1504165693' , 'Collective Data' , 'http://www.collectivedata.com' , 'IT' , 'USA');
insert into table_entities_RESULT values ('bloodsense','e109984','1504165620','BloodSense','http://just asample.com','Medical Devices','USA');
insert into table_entities_RESULT values ('e117385','','','TrendHealth Ltd','','Healthcare','');
insert into table_entities_RESULT values ('mando','','','Mando Health','','Healthcare','');
insert into table_entities_RESULT values ('e112481','','','Long View Med','','Medical Devices','');
insert into table_entities_RESULT values ('microsense','','','MicroSense LLC','','','USA');
insert into table_entities_RESULT values ('e114958','','','Telemed','','Medical Devices','');evices','');

感谢您尝试了解此新伙伴。 问候。

0 个答案:

没有答案