how to delete duplicate records in a table
Hi!
please i wanna update the content of my table for exemple, i have one table contains 4 names of movies , and all the 4 movies are the same Please can you give me a small script php to let only one of the 4 movies on my table structure of the table is : `id` | `name` | `categorie` | `synopsis` | `type` | `s` thank you !! ---------edit--------- Yes !! it's working great , juste one thing please , i wanna make the delecte from the beginning for exemple , the duplicate ID are number one : ID=5000 number two : ID=100 those two numbers are the same so, the one wich i wanna delected is ID=100 and the ID=5000 still in my database please, and thank you very much !!!
2 Answers
just change it to
$sql = @mysql_query("select * FROM `$table` order by id desc"); Posted: MacOS 1 of 1 people found this answer helpful. Did you? Yes No
i have an idea but first you have to take an backup
this is the code $table = \'\';//your table name $sql = @mysql_query(\"select * FROM `$table`\"); while($row = mysql_fetch_array($sql)) { $sql_de = @mysql_query(\"select * FROM `$table` where `name` LIKE \'%\".$row[\'name\'].\"%\' and id != \'\".$row[\'id\'].\"\'\"); while($de = @mysql_fetch_array($sql_de)) { if(mysql_query(\"delete from `$table` where id = \'\".$de[\'id\'].\"\'\")){ echo $de[\'name\'].\' has deleted beause there is other one with the same name <br>\'; } } }add your table name in $table Posted: xtremex 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved