Remove duplicate rows in MySQL

前端 未结 25 3475
囚心锁ツ
囚心锁ツ 2020-11-21 04:33

I have a table with the following fields:

id (Unique)
url (Unique)
title
company
site_id

Now, I need to remove rows having same titl

25条回答
  •  攒了一身酷
    2020-11-21 05:32

    You can easily delete the duplicate records from this code..

    $qry = mysql_query("SELECT * from cities");
    while($qry_row = mysql_fetch_array($qry))
    {
    $qry2 = mysql_query("SELECT * from cities2 where city = '".$qry_row['city']."'");
    
    if(mysql_num_rows($qry2) > 1){
        while($row = mysql_fetch_array($qry2)){
            $city_arry[] = $row;
    
            }
    
        $total = sizeof($city_arry) - 1;
            for($i=1; $i<=$total; $i++){
    
    
                mysql_query( "delete from cities2 where town_id = '".$city_arry[$i][0]."'");
    
                }
        }
        //exit;
    }
    

提交回复
热议问题