Solved

SQL SELECT DISTINCT Statement

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

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 …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

770 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