Sql-server – Copying distinct rows from one table to another

sql serversql-server-2008

In SQL Server, I can copy one table into another by doing:

Select * into desttable from sourcetable

However, there are duplicate rows in sourcetable and I would like to just copy distinct rows. How do I do this?

Thanks

Best Answer

If they are true EXACT duplicates, you can do:

SELECT DISTINCT *
INTO NewTable
FROM Sourcetable

If they aren't exact dupes in every single field, then we need more info.