Jump to content

Save First Record Delete Remaining Duplicate Record


lilmer

Recommended Posts

Good day, I want to know if I can save the first entry and delete the remaining duplicate enty.

This is what I did to get all the records with duplicate entry

SELECT  a.*, b.totalCount AS Duplicate
       FROM table a
       INNER JOIN
       (
          SELECT  email, COUNT(*) totalCount
          FROM    psuser
          GROUP   BY email
          HAVING  COUNT(*) >= 2
       ) b ON a.email = b.email
ORDER BY a.email,a.userId
Sample record result

ID , EMAIL 

100 , A
101 , A
102 , A
200 , B
222 , B
235 , C
262 , C
276 , D
278 , D
300 , E
301 , E
302 , E
305 , E

Don't delete the first entry  and delete all those remaining.  Can I do that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.