Solved

SQL SELECT DISTINCT Statement

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Viewers will learn how the fundamental information of how to create a table.

713 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