title: return latest version of a drupal node
body: <p>I'm writing a drupal module, and I need to write a query that returns particular rows of one of my content_type tables. My query so far is:</p>
  
  <pre><code>SELECT DISTINCT pb.*, f.filepath FROM {content_type_promo_box} pb LEFT JOIN {files} f ON pb.field_promo_image_fid = f.fid
  </code></pre>
  
  <p>I realized as I was working that the table not only contains each cck field of this content type, it also contains multiple <strong>versions</strong> for each field. How do I limit my query to the rows that only contain values for the <strong>current</strong> versions of the nodes?</p>
  
  <p>UPDATE: I need to clarify my question a little. I've been down the views path already, and I did think about using node_load (thanks for the answer, though, Jeremy!). Really, my question is more about how to write an appropriate SQL statement than it is about drupal specifically. I only want to return rows that contain the latest versions (vid is the greatest) for any particular node (nid). So here's an example:</p>
  
  <pre><code>-------------
  | nid | vid |
  -------------
  | 45  |  3  |
  | 23  |  5  |
  | 45  |  9  |
  | 23  |  12 |
  | 45  |  36 |
  | 33  |  44 |
  | 33  |  78 |
  ------------- 
  </code></pre>
  
  <p>My query should return the following:</p>
  
  <pre><code>-------------
  | nid | vid |
  -------------
  | 23  |  12 |
  | 45  |  36 |
  | 33  |  78 |
  -------------
  </code></pre>
  
  <p>Make sense? Thanks!</p>