title: Selecting distinct identity rows based on the lowest value of a joined priority column
body: <p>Simplified table structures, all INT columns and no PKs outside of the identity columns:</p>
  
  <p><strong>Nodes (n)</strong> table: <code>id</code></p>
  
  <p><strong>Attributes (a)</strong> table: <code>id</code>, <code>node_id</code>, <code>type_id</code></p>
  
  <p><strong>Type (t)</strong> table: <code>id</code>, <code>priority</code></p>
  
  <p>I'm trying to select a set of attributes, each of which has the lowest type.priority for its respective node. Though there are multiple attributes per <code>node_id</code>, I only want to select the one with the lowest priority value:</p>
  
  <pre><code>a1 n1 t1 p0 *
  a2 n1 t2 p1 
  a3 n2 t2 p1 *
  a4 n2 t3 p2  
  </code></pre>
  
  <p>This is the basic query that I'm working from, at which point I'm also getting stuck:</p>
  
  <pre><code>   SELECT * 
       FROM a 
  LEFT JOIN t ON a.type_id = t.id 
   GROUP BY node_id
  </code></pre>
  
  <p>My first thought was to use an aggregate, MIN, but I'm then having problems matching up the lowest priority for a node_id with the correct attribute.</p>