title: SQL If records are repetitive select the one with the max id
body: <p>I have a query that returns older versions of some records (due to bad database design) and i try to get only the newest ones. So i try to get the ones with Max Id's but query is complicated and there are lots of records. So subselect queries like this wont work:</p>
  
  <pre><code>SELECT row 
  FROM table 
  WHERE id=(
      SELECT max(id) FROM table
      )
  </code></pre>
  
  <p>And here's my query. By the way my company is using Testlink, if you're familiar with it and you have a better solution for this, it would be appreciated.</p>
  
  <pre><code>SELECT req_doc_id, scope,nh.parent_id,nh.id
  FROM (SELECT nh.id, req_doc_id,doc_id FROM nodes_hierarchy nh,
  req_specs r1, requirements r2 
  WHERE nh.parent_id = r1.id AND nh.id = r2.id 
  AND (r1.doc_id LIKE '%BlaBla%' OR r1.doc_id LIKE '%Tralala%')) 
  AS t1, nodes_hierarchy nh, req_versions r1 
  WHERE t1.id = nh.parent_id AND nh.id = r1.id
  </code></pre>
  
  <p>And resultset is</p>
  
  <pre><code> NAME..................ID              
  ____
  
  BlaBla1..............163        
  
  BlaBla1..............190
  
  BlaBla2..............173
  
  Tralala..............15
  
  Tralala2.............26
  
  Tralala2.............19
  </code></pre>
  
  <p>What I want is:</p>
  
  <pre><code> NAME..................ID              
  ____
  
  
  BlaBla1..............190
  
  BlaBla2..............173
  
  Tralala..............15
  
  Tralala2.............26
  </code></pre>