Link to home
Start Free TrialLog in
Avatar of Jim Metcalf
Jim MetcalfFlag for United States of America

asked on

deleting duplicates in a sql table

I have 7 columns.
i need rows to be deleted if there is a duplicate if all cells match between two rows on all 7 values.
is there an easy to do this?
Avatar of YZlat
YZlat
Flag of United States of America image

you could do the following:

1) Select all distinct rows into a new table
2) truncate your original table
3) copy rows from the table you created into the original table

SELECT DISTINCT col1,col2,col3
INTO   #staging
FROM   Table1

TRUNCATE TABLE Table1

INSERT INTO Table1 (col1,col2,col3)
SELECT col1,col2,col3
FROM #staging

Open in new window

you could also create a new regular table with the same structure, insert distinct data in that table, then delete your original table and rename new table to the same name as original table had
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial