#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    456
    Rep Power
    14
    I have a MySQL table that looks something like this:

    id url name

    1 http://www.yahoo.com Yahoo
    2 http://www.aol.com AOL
    3 http://www.excite.com Excite
    4 http://www.yahoo.com YAHOO!
    5 http://www.yahoo.com/abc Yahoo!

    Can someone give me the Perl code that could go through the MySQL table and remove entries with duplicate URLs? No consideration should be given to name. For this example 1 and 4 should be considered duplicates. 4 should be removed and 1 should stay. 6 should not be regarded as a duplicate.

    I appreciate the help!

    Ryan McKillen

    [This message has been edited by scream (edited October 03, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Well you should have made the field unique in the 1st place. The easiest way (if it works) to fix it is to alter the table and make the field a unique key.

    If that doesn't work you'll have to do some working with arrays/hashs and get it fixed.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    114
    Rep Power
    14
    what would happen if you used a query to create a new table with just distinct entries?

    mysql>CREATE distinct_urls SELECT id, url, name
    ->FROM your_table
    ->GROUP BY url;

    That query would create a new table with just the distinct URL's, an id from one of them, an a name from one of them. I don't know if you could control whether or not 1 became 4, or 4 became 1. At any rate, it's worth a try.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    456
    Rep Power
    14
    Thanks for the input. Your suggestions allowed me to accomplish what I was hoping for!

IMN logo majestic logo threadwatch logo seochat tools logo