title: How can SQLAlchemy get the maximum value of a field?
body: <p>I have the following SQLAlchemy class/model:</p>
  
  <pre><code>class MyModel(db.Model):
      my_id = db.Column(db.Integer, nullable=False, primary_key=True)
      my_field = db.Column(db.String(128))
  </code></pre>
  
  <p>How do I find the maximum value of <code>my_id</code> in the table?</p>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/14217860/how-to-select-min-and-max-from-table-by-column-score">this soluttion</a>, however, that seems like such an ugly way to do it (and I don't even know how to apply it in my case!). When I want to query this table, I do something like this:</p>
  
  <pre><code>MyModel.query.filter(MyModel.my_field == "blah").one()
  </code></pre>
  
  <p>Can't I do something very similar to this to find the max value of <code>my_id</code>? 
  Ideally, I would just replace the stuff inside <code>filter(...)</code></p>