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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.