Hello,
I have the following table:
I am looking for a way to remove the duplicate recordid, docno, bookno, pageno values. I don't care which one stays, but I just want one of each instance to stay. So results like:
relatedid, recordid, docno, bookno, pageno
1, 89, '12345', '100', '444'
4, 90, '55555', '200', '555'
6, 91, '77777', '300', '888'
I am writing something that is just turning into a whole bunch of #temp tables and turning into kind of a mess. I think I am making it way to hard.. there has to be a better solution out there. Any ideas?
Thanks!
I have the following table:
Code:
create table #temp (relatedid int, recordid int, docno varchar(20), bookno varchar(20), pageno varchar(20))
insert into #temp values (1, 89, '12345', '100', '444')
insert into #temp values (2, 89, '12345', '100', '444')
insert into #temp values (3, 89, '12345', '100', '444')
insert into #temp values (4, 90, '55555', '200', '555')
insert into #temp values (5, 90, '55555', '200', '555')
insert into #temp values (6, 91, '77777', '300', '888')
insert into #temp values (7, 91, '77777', '300', '888')
insert into #temp values (8, 91, '77777', '300', '888')
insert into #temp values (9, 91, '77777', '300', '888')
I am looking for a way to remove the duplicate recordid, docno, bookno, pageno values. I don't care which one stays, but I just want one of each instance to stay. So results like:
relatedid, recordid, docno, bookno, pageno
1, 89, '12345', '100', '444'
4, 90, '55555', '200', '555'
6, 91, '77777', '300', '888'
I am writing something that is just turning into a whole bunch of #temp tables and turning into kind of a mess. I think I am making it way to hard.. there has to be a better solution out there. Any ideas?
Thanks!