GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php / Mysql help needed... (https://gfy.com/showthread.php?t=440124)

4Pics 03-04-2005 10:33 PM

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

brutus 03-04-2005 10:36 PM

/
dev nul

teksonline 03-04-2005 11:00 PM

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

rickholio 03-04-2005 11:09 PM

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. :thumbsup

SMG 03-04-2005 11:15 PM

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.

4Pics 03-05-2005 01:32 AM

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. :thumbsup

Awesome, that alter thing was the easiest way!

thank you!

rickholio 03-05-2005 01:37 AM

Quote:

Originally Posted by 4Pics
Awesome, that alter thing was the easiest way!

thank you!

:thumbsup


All times are GMT -7. The time now is 03:33 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123