Solved

SQL SELECT DISTINCT Statement

Posted on 2011-03-09
5
257 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
Oh ok, can you write me a basic SQL statement that does this.
0
 
LVL 142

Expert Comment

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

Expert Comment

by:wdosanjos
Comment Utility
@yguyon28:

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

Expert Comment

by:wdosanjos
Comment Utility
Also, does your table have a primary key?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now