Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:24:22+00:00 2026-06-14T15:24:22+00:00

Everything I have searched for and found has yet to work because I am

  • 0

Everything I have searched for and found has yet to work because I am accessing the Table through a php script and differently than everything I see. Anyways,
I am importing Feeds from a website into a mysql table. My table was created like this…

$query2 = <<<EOQ
CREATE TABLE IF NOT EXISTS `Entries` (
`feed_id` int(11) NOT NULL,
`item_title` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`item_link` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`item_date` varchar(40) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
EOQ;
$result = $db_obj->query($query2);

I enter the data like so….

foreach($rss->channel->item as $Item){
$query5 = <<<EOQ
INSERT INTO Entries (feed_id, item_title, item_link, item_date)
VALUES ('$get_id','$Item->title','$Item->link','$Item->pubDate')
EOQ;
$result = $db_obj->query($query5);
}

Now, every time Import new feeds from the site I want to make sure I delete any duplicates that might already be there. Everything I have tried, especially DISTINCT, has not worked for me. Does anyone know what type of query I could use to create a temp table, copy over any distinct rows (ENTIRE ROWS, if a title is the same but the date is different I want to keep that), drop the old table, then rename the tamp table to what I want…. or something similar?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:24:23+00:00Added an answer on June 14, 2026 at 3:24 pm

    Avoid using the duplicate rows in the first place. Make any unique values into keys. When adding new values to your database, use

    REPLACE INTO Entries (feed_id, item_title, item_link, item_date)
    VALUES ('$get_id','$Item->title','$Item->link','$Item->pubDate')
    EOQ;
    

    The duplicates will be automatically overwritten. Replace is handy because it works like an insert when there is no conflict in the keys, but when there is then it will update the record and bump up any auto-incrementing keys.

    EDIT

    I’ve been drumming over this for a while. Here’s what I came up with.

    The problem with making a multi-column key on (feed_id, item_title, item_link, item_date) is that it will exceed the 1000 byte limitation in MySQL for key length. So instead alter your schema like so:

    CREATE TABLE IF NOT EXISTS `Entries` (
    `hash` varchar(32),
    `feed_id` int(11) NOT NULL,
    `item_title` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
    `item_link` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
    `item_date` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
     PRIMARY KEY (hash)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
    

    Now when you store a new value, get a hash of the values together:

    $hash = md5($get_id . $Item->title . $Item->link . $Item->pubDate);
    

    And for your insert statements use the following:

    REPLACE INTO Entries (hash, feed_id, item_title, item_link, item_date)
    VALUES ('$hash', '$get_id','$Item->title','$Item->link','$Item->pubDate')
    EOQ;
    

    The hash will be a unique representation of the record in it’s entirety, and will be easy to compare in order to avoid duplicates. Now when you attempt to add the same record more than once, it will just replace the existing entry, and your query will not fail. As an alternative, you could continue to use insert, and the query will return an error, which you could handle however you want to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried everything, searched the net for two hours or even more and
Rather than have everything in one big dialog, I'm looking at being able to
I have searched the web for resolution of this error, but everything I have
So I have this problem when I run a script with PHP PDO that
I have a javascript file linked to a PHP page which has a value
I've searched for several hours and tried out everything I found, but nothing helped,
I have searched Google and looked here but I haven't quite found the answer
I've extensively searched the web, and everything I've found suggests that I can use
I have searched for a few hours already but have found nothing on the
I have everything same in 10.04 LTS, local in parallels 7 On ec2 instances

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.