title: Find duplicate rows in mysql simplified example
body: <p>Confession: a mysql newb requires simple example to locate duplicate rows in somewhat large table. I have searched for and read many other threads with similar titles, but the examples are so complex that I cannot apply them to my basic situation.</p>
  
  <p>A MySQL table has only 5 fields, but there are hundreds of rows. I wish to locate duplicate rows -- I know there is one for sure and wonder if there are others.</p>
  
  <p>Example Row: (rel_id is auto-incrementing, primary key field)</p>
  
  <pre><code>'rel_id' =&gt; 1
  'host' =&gt; 17
  'host_type' =&gt; 'client'
  'rep' =&gt; 7
  'rep_type =&gt; 'cli_mgr'
  </code></pre>
  
  <p>My approach was to:<br>
  1. Read entire table into mysql query<br>
  2. row-by-row compare the 4 data fields to those of previous ("done") rows<br>
  3. after comparing a "new" row, append it to array of "done" rows<br></p>
  
  <p>Here is what I have tried. I am sure that there must be a much simpler solution. You will see that I am bogged down in trying to append the "new" row to the array of "done" rows:</p>
  
  <pre><code>$rRels = mysql_query("SELECT * FROM `rels`");
  $a = array();
  $e = array();
  $c1 = 0;
  $c2 = 0;
  While ($r = mysql_fetch_assoc($rRels)) {
      $i = $r['rel_id'];
      $h = $r['host'];
      $ht = $r['host_type'];
      $r = $r['rep'];
      $rt = $r['rep_type'];
  
      foreach($a as $row) {
          $xh = $row['host'];
          $xht = $row['host_type'];
          $xr = $row['rel'];
          $xrt = $row['rel_type'];
  
          if (($h==$xh) &amp;&amp; ($ht==$xht) &amp;&amp; ($r==$xr) &amp;&amp; ($rt==$xrt)) {
              echo 'Found one&lt;br&gt;';
              $e[] = $r;
          }
          $c2++;
      }
      $a = array_merge(array('rel_id'=&gt;$i, 'host'=&gt;$h, 'host_type'=&gt;$ht, 'rep'=&gt;$r, 'rep_type'=&gt;$rt), $a);
      $c1++;
  }
  
  echo '&lt;h3&gt;Duplicate Rows:&lt;/h3&gt;';
  foreach ($e as $row) {
      print_r($row);
      echo '&lt;br&gt;';
  }
  echo '&lt;br&gt;&lt;br&gt;';
  echo 'Counter 1: ' . $c1 . '&lt;br&gt;';
  echo 'Counter 2: ' . $c2 . '&lt;br&gt;';
  </code></pre>