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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.