Solved

Delete duplicates from SQL table based on dupe email addresses

Posted on 2009-07-15
4
298 Views
Last Modified: 2012-05-07
I have an SQL table that has a little more than 1,000 records. When I use 'distinct *' to select distinct records into a new table, and then look at email addresses, there are still duplicate records! Why is this?

Can anyone tell me how to delete rows of table data based on dupe email addresses? if I can kill the dupes by looking at the email addresses this would fix my problem. My email address field is called EmailAddr.....and there's no defined primary key on this table. Thanks...
0
Comment
Question by:jazjef
[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
4 Comments
 
LVL 8

Expert Comment

by:vsudip
ID: 24860498
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24860499
Seems like you have differebbt data in one of the other columns
for example

Col 1   col2
a         b
a        c

if you select DISTINCT * from the above table it still returns 2 records

http://sequelserver.blogspot.com/2008/02/deleting-duplicate-records.html
0
 
LVL 8

Accepted Solution

by:
MartinCMS earned 500 total points
ID: 24860745
Try this query

DELETE FROM yourTable
WHERE EXISTS (SELECT 1
            FROM   yourTable AS yt2
            WHERE  yt2.EmailAddr= yourTable.EmailAddrAND
                     yt2.Record_ID < yourTable.Record_ID)

*** Record_ID - could be the record sequence field in your table
0
 
LVL 4

Author Closing Comment

by:jazjef
ID: 31603975
Thanks MartinCMS... I just added the Record_ID field and your statement worked great!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

626 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