title: Get Latest ID from a Duplicate Records in a table
body: <p>so i have two tables, one is RAWtable and the other is MAINtable, I have to get the latest groupID if there
  are more than one records exist (comparing same name, code). For example, I have this on RAWtable:</p>
  
  <pre><code>id  groupid     name        code
  1   G09161405   Name1       Code1
  2   G09161406   Name1       Code1
  </code></pre>
  
  <p>the two records should be treated as one and should return this value only:</p>
  
  <pre><code>id  groupid     name        code
  2   G09161406   Name1       Code1
  </code></pre>
  
  <p>This row is the only row that shiuld be inserted in the main table. Provided returning the latest GroupID (the groupid is the combination of date and time)</p>
  
  <p>I've tried this but its not working:</p>
  
  <pre><code>SELECT MAST.ID, MAST.code, MAST.name FROM RAWtable AS MAST INNER JOIN 
  (SELECT code, name, grouid,id FROM RAWtable AS DUPT GROUP BY code, name, groupid,id HAVING COUNT(*) &gt;= 2) DUPT
   ON  DUPT.code =MAST.code and DUPT.name =MAST.name where dupt.groupid &gt;mast.groupid 
  </code></pre>
  
  <p>how can i do this? thanks a lot.</p>