Solved

SQL SELECT DISTINCT Statement

Posted on 2011-03-09
5
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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

631 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