title: SqlAlchemy select with max, group_by and order_by
body: <p>I have to list the last modified resources for each group, for that I can do this query:</p>
  
  <pre><code>model.Session.query(
      model.Resource, func.max(model.Resource.last_modified)
  ).group_by(model.Resource.resource_group_id).order_by(
      model.Resource.last_modified.desc())
  </code></pre>
  
  <p>But SqlAlchemy complains with:</p>
  
  <pre><code>ProgrammingError: (ProgrammingError) column "resource.id" must appear in
  the GROUP BY clause or be used in an aggregate function
  </code></pre>
  
  <p>How I can select only resource_group_id and last_modified columns?</p>
  
  <p>In SQL what I want is this:</p>
  
  <pre><code>SELECT resource_group_id, max(last_modified) AS max_1
  FROM resource GROUP BY resource_group_id ORDER BY max_1 DESC
  </code></pre>