suttercain Posted April 9, 2008 Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100336-find-duplicate-rows-in-mysql/ Share on other sites More sharing options...
GingerRobot Posted April 9, 2008 Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100336-find-duplicate-rows-in-mysql/#findComment-513102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.