title: drupal 7 sql syntax
body: <p>i'm trying to get a results set that displays 2 columns from 2 different tables, grouping by one column and summing the other.</p>
  
  <p>this sql works in phpmyadmin:</p>
  
  <pre><code>SELECT SUM(field_count_value), field_region_value
  FROM field_data_field_count, field_data_field_region
  WHERE field_data_field_count.entity_id = field_data_field_region.entity_id
  GROUP BY field_data_field_region.field_region_value
  ORDER BY field_count_value DESC
  </code></pre>
  
  <p>displaying roughly what i need::</p>
  
  <pre><code>-----------------
  COUNT    REGION
  -----------------
  4000     S
  600      E
  -----------------
  </code></pre>
  
  <p>but when i convert it to drupal 7 sql query syntax:</p>
  
  <pre><code>$nodes = db_query("SELECT SUM(field_count_value), field_region_value
  FROM field_data_field_count, field_data_field_region
  WHERE field_data_field_count.entity_id = field_data_field_region.entity_id
  GROUP BY field_data_field_region.field_region_value
  ORDER BY field_count_value DESC");
  
  foreach ($nodes as $record) {
    echo $record-&gt;field_region_value . $record-&gt;field_count_value; 
    }
  </code></pre>
  
  <p>i can only get the group by column to display:</p>
  
  <pre><code>-----------------
  REGION
  -----------------
  S
  E
  -----------------
  </code></pre>
  
  <p>any help would be greatly appreciated. i've consulted the official d7 docs to get this far -- not very many examples to work from there.</p>