karimali831 Posted July 7, 2010 Share Posted July 7, 2010 Hi I want to check for duplicates in a column. can someone provide the query please? Link to comment https://forums.phpfreaks.com/topic/207065-sql-check-duplicates/ Share on other sites More sharing options...
Pikachu2000 Posted July 7, 2010 Share Posted July 7, 2010 Is this the same issue as in the other thread you started? People are already trying to help you in that one. Link to comment https://forums.phpfreaks.com/topic/207065-sql-check-duplicates/#findComment-1082728 Share on other sites More sharing options...
karimali831 Posted July 7, 2010 Author Share Posted July 7, 2010 other one is the insert question and this one is checking, so I need query please. Different question, different topic, new thread? Link to comment https://forums.phpfreaks.com/topic/207065-sql-check-duplicates/#findComment-1082730 Share on other sites More sharing options...
Pikachu2000 Posted July 7, 2010 Share Posted July 7, 2010 I've actually been needing something like this for a site I'm working on, so I sat down and figured it out. The table returns the duplicate value in the field, and the total number of entries the value has. I have it in a function, but this is the guts of it, with an echo() instead of return(). $field = 'your_field'; $table = 'your_table'; require_once("your_db_conn_script"); $output = ''; $query = "SELECT `{$field}`, COUNT(`{$field}`) AS c FROM `{$table}` GROUP BY `{$field}` ORDER BY c DESC"; $result = mysql_query( $query ); $output = "<table>"; while( $array = mysql_fetch_assoc($result) ) { if( $array['c'] > 1 ) { $bg != "CCCCCC" ? $bg = "CCCCCC" : $bg = "FFFFFF"; $count = $array['c']; $output .= "<tr bgcolor=\"$bg\"><td>Value:</td><td>" . $array['ident'] . "</td><td>Entries:</td><td>" . $count . "</td></tr>"; } } $output .= "</table>"; echo $output; } Link to comment https://forums.phpfreaks.com/topic/207065-sql-check-duplicates/#findComment-1082773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.