954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Remove duplicate entries

I am using MySQL to store the RSS feed contents that are updated every few hours. I truncate the database once a day. But during the day, whenever same feeds are updated every few hours I get duplicate entries piled up. Is there any PHP script that I can run to remove those duplicate entries?

s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

Why not make that entry a unique index, then you can use a query that updates that index if it cannot be inserted (due to it being already there).

http://dev.mysql.com/doc/refman/5.6/en/insert-on-duplicate.html

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This is a very good idea, but how can I make it unique when all the columns are variable. Here's what I am loading the table with:

mysql_query("INSERT INTO data values('$title','$link','$description','$date')");


When I re-run my script, all those entries are duplicated in the table. I want to make $title as unique and that will be compared for removal of duplicate entries.

Thanks for your help.

s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

Set column `title` as primary key or unique index.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

OK I changed it to unique index. Now how I do relate it to the example provided in the initial link that you provided? I am little confused.. please help out here!~

INSERT INTO table (a,b,c) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE c=c+1;

UPDATE table SET c=c+1 WHERE a=1;
s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

Something like this will insert a new title, or update an existing one with newer additional columns (if that is what you want).

mysql_query("
  INSERT INTO data VALUES ('$title', '$link', '$description', '$date')
  ON DUPLICATE KEY UPDATE link = '$link', description = '$description', date = '$date'
");
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Cool.. you are awesome!

s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You