Jump to content

Set Unique indices but duplicate rows


optikalefx

Recommended Posts

Firstly BACKUP the original db.

 

I would create a new table with an id field with Auto Increment set then use something like this: 

 

SELECT distinct email FROM originaltable WHERE id > 0

 

Get the results of that query and then paste them into this.

 

INSERT INTO newtable SET email = value1, name = value2.....then any other fields.

 

Hope this helps.

  • 2 weeks later...

I wrote this a while back to check a single field in a table for duplicate entries. You should be able to use it or modify it to at least build the list of duplicates.

 

<?php
function mysqli_check_duplicates($db_conn, $table, $field, $flag = 1) {
    $field = $field;
    $table = $table;
    require_once("$db_conn");
    $output = '';
    $query = "SELECT `{$field}`, COUNT(`{$field}`) AS c FROM `{$table}` GROUP BY `{$field}` ORDER BY c DESC";
    $result = mysqli_query( $dbc, $query );
    $output = "<table>";

    while( $array = mysqli_fetch_assoc($result) ) {
        if( $array['c'] > $flag ) {
            $bg != "CCCCCC" ? $bg = "CCCCCC" : $bg = "FFFFFF";
            $count = $array['c'];
            $output .=  "<tr bgcolor=\"$bg\"><td>Value:</td><td>" . $array[$field] . "</td><td>Entries:</td><td>" . $count . "</td></tr>";
        }
    }
    $output .= "</table>";
    return $output;
}

// mysqli_check_duplicates('db_conn_with_path', 'table_name', 'field_name', $flag); // $flag - 0 = show all rows, 1 = (default) only show duplicates
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.