Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL SELECT DISTINCT Statement

Posted on 2011-03-09
5
Medium Priority
?
268 Views
Last Modified: 2012-05-11
How do I write a Select Distinct statement that delete duplicate data from a table and dump the result to another table?
0
Comment
Question by:yguyon28
  • 2
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35083911
you can do both in 1 statement with sql 2005+:
using the DELETE ... OUTPUT ... INTO @table   followed by INSERT INTO othertable ... SELECT ... FROM @table
see here:
http://msdn.microsoft.com/en-us/library/ms177564.aspx
0
 

Author Comment

by:yguyon28
ID: 35083984
Oh ok, can you write me a basic SQL statement that does this.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35084093
please see example F on the linked page
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35084277
@yguyon28:

Do all columns in your table indicate a duplicate record?  Or just a few columns?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35084309
Also, does your table have a primary key?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question