My manager and I where looking at some complex code to eliminate duplicate records in a database table.
then it hit me how its done easily... so i thought i'd share it...
In English:
--------------------------------
-- Eliminating Duplicate rows --
--------------------------------
-- select all into a temp table.
-- truncate origional table.
-- select only unique rows back into origional table.
In Code sql server 2000:
--------------------------------
-- Eliminating Duplicate rows --
--------------------------------
[code=sql]
-- select all into a temp table.
select * into temptable1 from <OrigionalTable >
-- truncate origional table.
delete <OrigionalTable >
-- select only unique rows back inot origional table.
--this usues the selected columns to see if its unique
insert into <OrigionalTable > select Distinct <columnName> from TempTable1
--this uses all columnsto see if its unique
insert into <OrigionalTable > select Distinct * from TempTable1
[/code]
then it hit me how its done easily... so i thought i'd share it...
In English:
--------------------------------
-- Eliminating Duplicate rows --
--------------------------------
-- select all into a temp table.
-- truncate origional table.
-- select only unique rows back into origional table.
In Code sql server 2000:
--------------------------------
-- Eliminating Duplicate rows --
--------------------------------
[code=sql]
-- select all into a temp table.
select * into temptable1 from <OrigionalTable >
-- truncate origional table.
delete <OrigionalTable >
-- select only unique rows back inot origional table.
--this usues the selected columns to see if its unique
insert into <OrigionalTable > select Distinct <columnName> from TempTable1
--this uses all columnsto see if its unique
insert into <OrigionalTable > select Distinct * from TempTable1
[/code]
Comment