sql - Combining match groups from different tables -
please see ddl below:
create table dbmatch1 (_key_out int, reference int, dataset varchar(100), drivinglicense varchar(100), name varchar(100), dateofbirth datetime) insert dbmatch1 values (1,1,'sales', '','richard williams','1980-11-07') insert dbmatch1 values (1,86,'production', '','richard williams','1980-11-07') insert dbmatch1 values( 1,1008,'finance', 'jdhdhdh8333','richard williams','1980-11-07') insert dbmatch1 values (2,90,'marketing', '','dick williams','1980-11-07') insert dbmatch1 values (3,251,'sales', '','ian mcwilliams','1971-02-02') create table dbmatch2 (_key_out int, reference int, dataset varchar(100), drivinglicense varchar(100),name varchar(100), dateofbirth datetime) insert dbmatch2 values (100,1008,'finance', 'jdhdhdh8333','richard williams','1980-11-07') insert dbmatch2 values (100,90,'marketing', 'jdhdhdh8333','','') insert dbmatch2 values (100,95,'sales', 'jdhdhdh8333','','') insert dbmatch2 values (101,45,'production', 'jlbfjldfnl','','') insert dbmatch2 values (102,455,'marketing', 'jlbfjldfnl','','') the _key_out column identifies records duplicates. sales record 1, production record 86 , finance record 1008 duplicates dbmatch1 , finance record 1008, marketing record 90 , sales record 95 duplicates dbmatch 2.
how combine these results? example, first 3 records dbmatch1 , first 2 records dbmatch2 part of same group.
i have tried this:
select * dbmatch1 union select * dbmatch2
the problem _key_out ids not same following rows:
1 1 sales richard williams 1980-11-07 00:00:00.000 1 86 production richard williams 1980-11-07 00:00:00.000 1 1008 finance jdhdhdh8333 richard williams 1980-11-07 00:00:00.000 100 90 marketing jdhdhdh8333 1900-01-01 00:00:00.000 100 95 sales jdhdhdh8333 1900-01-01 00:00:00.000 100 1008 finance jdhdhdh8333 richard williams 1980-11-07 00:00:00.000
i not sure have tried can't use union merge result like
(select * dbmatch1) -- giving first part duplicates union (select * dbmatch2) -- giving second part duplicates
Comments
Post a Comment