Have an account? Sign in
Login  Register  Facebook
how to delete duplicate records in a table
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 !!
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
and thank you very much !!!
Started: September 18, 2011 Latest Activity: September 18, 2011 sql php
2 Answers
just change it to
$sql = @mysql_query("select * FROM `$table` order by id desc");

Posted: MacOS
In: September 18, 2011

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
In: September 18, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer