Dear All,

I am interested in performing a sub query that  removes duplicate records from
a temporary table prior to pushing the data to the main table.

I am not sure if it is possible and thought I would ask prior to the endeavor.

I currently use php to perform this operation but is really bogs down the db.

Here is the code example i am using now to perform this function:

// select the name from the dedup row

$sql = "select name,id from dedup";

$ret = run_query($sql);

// loop through and check if the name exists in the lead table

while($ddRow=mysql_fetch_assoc($ret)){

        $sql2 = "select name,id from leads where name LIKE '$ddupRow[name]'";
        $ret2 = run_query($sql2);

     // if rows returned is greater than 0 delete from the dedup table

        if(myqsl_num_rows( $ret2 ) > 0){

            $del_sql = "DELETE FROM dedup WHERE id = '$ddRow[id]'";
            run_query($del_sql);

       // else insert the new record

       }else{
        $iQ="INSERT into leads (name) VALUES ( '$ddupRow[name]')";
;       run_query($iQ);
    }
}


I am wondering if it is possible to do this with one query without the double 
hit to the DB?
Or ,if possible, perform one large query and remove the duplicates in one blow?

Any thought or suggestions would be very much appreciated.

Kind Regards,

Paul



      

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to