php - (my)SQL delete duplicate DB-entries WHERE ... -
this question has reply here:
how delete duplicates on mysql table? 10 answershi got db this
db-name: plzahl sample data: code | plz ------------------ 1 8000 1 8000 2 8000 3 8000 2 8001 3 8001 ...
what want delete duplicates leave 1 in table highest "code" column value.
i have not yet unique identifier @ database. improve add together 1 , utilize mysql_fetch_array() , build "deleting array" or utilize foreach fetch "plz", search if count >0 , if, fetch them, sort them , delete count-1 ones?
so far:
<?php mysql_connect("localhost", "mysql_user", "mysql_password") or die("no connection: " . mysql_error()); mysql_select_db("mydb"); $result = mysql_query("select code, plz plzahl"); while ($row = mysql_fetch_array($result, mysql_num)) { //... here goes magic // create query search count $row['plz'] > 0 ? .... } mysql_free_result($result); ?>
thanks code hint!!
do mysql way:
mysql_query('create table plz_new plz'); mysql_query('insert plz (select max(code) code, plz plzahl grouping plz)'); mysql_query('drop table plz'); mysql_query('rename table plz_new plz');
php mysql sql duplicates
No comments:
Post a Comment