Jump to content

Easy way of deleting duplicates in mysql


brown2005

Recommended Posts

Well if you're using a script to have it be inserted into the database you could do.

 

$sql = "SELECT * FROM `table` WHERE `field1` ='$field1'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
//dont insert
}else {
//insert query
}

Link to comment
Share on other sites

SQL query: 

 

DELETE FROM tablea WHERE email IN (

 

SELECT email

FROM tablea

GROUP BY email

HAVING COUNT( * ) >1

)

 

MySQL said: 

 

#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT email

FROM tablea

GROUP BY email

HAVING COUNT(*) >

 

i get that mate

Link to comment
Share on other sites

Yes, that's what I need.  Furthermore let me explain something before I wipe out your data.  The SQL I gave you will delete all duplicates in the literal sense.  That is, any email which appears more than once will be wiped out.  So if the email patrick@foo.com appeared twice, after running the query all records containing that email address would be deleted.  I don't think, looking at your query, that is your intention.  It seems that you want to delete all subsequent duplicate email addresses, preserving the original.  Let me know if this sounds right.

 

Patrick

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.