Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

share|improve this question
4  
The clue is in the question :) –  Phil May 16 '12 at 12:47
1  
Very zen, @Phil –  JNK May 16 '12 at 13:00

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
select distinct *
into YourDestTable
from YourSourceTable

This will select only distinct rows into YourDestTable upon creation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.