Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 03-04-2005, 10:33 PM   #1
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
Php / Mysql help needed...

Anyone have code or know how to delete duplicate rows in a larger database. I have about 55k rows and want to remove all the duplicate urls in it.

Thanks
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2005, 10:36 PM   #2
brutus
Confirmed User
 
Join Date: Mar 2002
Location: Living in the bottle.
Posts: 590
/
dev nul
__________________
brutus is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2005, 11:00 PM   #3
teksonline
So Fucking Banned
 
Join Date: Jan 2005
Location: At My Desk
Posts: 2,904
delete

backup first

if you know what your deleting

"hair in my cabbage" is all the data in that field for example

delete from <table> where <tableelement> LIKE 'hair in my cabbage'

backup first!!!!!!!!! dont blame me later
teksonline is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2005, 11:09 PM   #4
rickholio
Confirmed User
 
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
Quote:
Originally Posted by 4Pics
Anyone have code or know how to delete duplicate rows in a larger database. I have about 55k rows and want to remove all the duplicate urls in it.

Thanks
I'd suggest that the easiest way to do it is through a temporary table... do a SELECT DISTINCT into the temp table to eliminate the duplicates.

Alternately, a cute way to do a de-facto culling is to ALTER TABLE and make your url column UNIQUE, ignoring (and therefore dropping) duplicates:

ALTER IGNORE TABLE sometable ADD UNIQUE (url)

... which would serve the additional purpose of permanently removing the possibility of duplicate URLs in the future, as well.

Obviously you'll want to back up everything before you try any of this.
rickholio is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2005, 11:15 PM   #5
SMG
Confirmed User
 
Join Date: Aug 2003
Posts: 1,798
I'd do something like this (but backup first)

$rs = mysql_query("SELECT id, url FROM your_table ORDER BY id ASC");
while (list($id,$url)=mysql_fetch_row($rs)) {
mysql_query("DELETE FROM your_table WHERE url = '$url' AND id != '$id'");
}

that will go through all your rows and delete all duplicates other than the first one ... you could change ASC to DESC to make it delete all but the newest ... obviously you have to probably change the field and table names though.
__________________
TGP Webmasters: sign up for the top 100 tgp list!
Submit galleries
If you add me to icq (title) make sure to mention GFY or I'll think you're a bot and deny you.
SMG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-05-2005, 01:32 AM   #6
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
Quote:
Originally Posted by rickholio
I'd suggest that the easiest way to do it is through a temporary table... do a SELECT DISTINCT into the temp table to eliminate the duplicates.

Alternately, a cute way to do a de-facto culling is to ALTER TABLE and make your url column UNIQUE, ignoring (and therefore dropping) duplicates:

ALTER IGNORE TABLE sometable ADD UNIQUE (url)

... which would serve the additional purpose of permanently removing the possibility of duplicate URLs in the future, as well.

Obviously you'll want to back up everything before you try any of this.
Awesome, that alter thing was the easiest way!

thank you!
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-05-2005, 01:37 AM   #7
rickholio
Confirmed User
 
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
Quote:
Originally Posted by 4Pics
Awesome, that alter thing was the easiest way!

thank you!
rickholio is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.