LDRNSJ
LDRNSJ

Reputation: 21

SEARCH and eliminate duplicate row on 2 table

im new on SQL and trying to create a table based on two tables. I have two tables with 7 columns each one some registers had incomplete information BUT i need to filter this.

Conditions. -cannot have duplicates on ID_1 on result table. "easy i think use distinct and i have the non duplicated" -cannot have duplicates on ID's 1-2. But if i have one i need to copy the row that contain more information.

I will attach the information about task and my code that is newbie at all

    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

So thats the first problem when i insert i had one duplicate because compare all registers in file and dont fill like i wish.

Click here

The expected output is THIS:

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','');

thanks for try to understand a new mate on this. Regards.

Upvotes: 2

Views: 50

Answers (0)

Related Questions