I've got a mental block on this one - maybe you can help.
I need to populate Table ABC from Table DEF. There are multiple columns but I need to ensure that I don't get duplicates based on a smaller group of those columns.
Assume both tables have columns A, B, C, D, E, F
and both tables are identical in their design.
If I want a list in Table ABC where there are no duplicate values in column C, then something like this would be close:
insert into ABC
select * from DEF where C not in (select c from ABC)
But that doesn't prohibit the possibility of more than one record from table DEF with the same value of column C. I can't do a SELECT DISTINCT because I can't populate all the columns when I do that.
It appears to get worse when its a multiple key thing like no duplicates on columns C & D. Then this would again be close:
insert into ABC
select * from DEF where C+D not in (select c+D from ABC)
Same problem as before plus this works only on certain data types for column C & D. If my C & D columns are mixed data types or say INT, then I guess a bunch of casts are needed.
Anyone have any good suggestions on how to do this efficently? Appreciate the help.
I need to populate Table ABC from Table DEF. There are multiple columns but I need to ensure that I don't get duplicates based on a smaller group of those columns.
Assume both tables have columns A, B, C, D, E, F
and both tables are identical in their design.
If I want a list in Table ABC where there are no duplicate values in column C, then something like this would be close:
insert into ABC
select * from DEF where C not in (select c from ABC)
But that doesn't prohibit the possibility of more than one record from table DEF with the same value of column C. I can't do a SELECT DISTINCT because I can't populate all the columns when I do that.
It appears to get worse when its a multiple key thing like no duplicates on columns C & D. Then this would again be close:
insert into ABC
select * from DEF where C+D not in (select c+D from ABC)
Same problem as before plus this works only on certain data types for column C & D. If my C & D columns are mixed data types or say INT, then I guess a bunch of casts are needed.
Anyone have any good suggestions on how to do this efficently? Appreciate the help.