Jump to content

Find Duplicate Rows in MySQL


suttercain

Recommended Posts

Hi everyone,

 

I have a table that contains about 18,000 records. The table has a primary key (unique id) and 21 columns.

 

Is there an easy way to locate duplicate rows? I would like to find a rows with the same data, with the exception of the primary key.

 

Thanks.

 

SC

Link to comment
Share on other sites

So you want to find rows where the 20 columns (all but the primary key) are duplicates?

 

<?php
$fields = array('field1','field2','field3');//list your fields
$sql = "SELECT * FROM users WHERE (`".implode('`,`',$fields)."`) IN(SELECT ".implode('`,`',$fields)." FROM users GROUP BY first,last)";
$result = mysql_query($sql) or die(mysql_error());
//show results
?>

 

If you dont also want to return the primary key, just use the inner query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.