title: Delete duplicate primary keys from a Mysql database using php programming
body: <p>I have three fields in my database: first name, lastname and email. Email is my primary key. I don't have any other fields in my database.</p>
  
  <p>I need to find a mysql query which can delete duplicated primary keys and their values from the database leaving only one unique email in the database.</p>
  
  <p>I use the following command to display all duplicated primary keys. It worked, but I need to delete all other duplicate entries and keep only one. I am using php programming.</p>
  
  <pre><code>SELECT *
  FROM table_name
  WHERE primarykey IN (
  SELECT primarykey
  FROM table_name
  GROUP BY primarykey
  HAVING count(primarykey) &gt; 1
  )
  ORDER BY primarykey
  </code></pre>