title: How to find the last entry and not the first when using INNER JOIN and CAST?
body: <p>My virtual radar program maintains a SQLite3 database. In the database are 2 tables, Aircraft and Flights. The first stores aircraft data and the other flights a particular aircraft made.
  I'd like to get a list of aircraft that do not have a flight in the last 180 days.
  Reading on the Internet I could create this query:</p>
  <pre><code>SELECT Registration,
         STRFTIME('%d-%m-%Y',Flights.EndTime) AS 'Last Flight',
         Flights.Callsign,
         CAST ((JULIANDAY('now') - JULIANDAY(Flights.EndTime)) AS INTEGER) AS 
         'Days unseen'
  FROM   Aircraft
         INNER JOIN Flights ON (Aircraft.AircraftID=Flights.AircraftID)
  WHERE
         CAST ((JULIANDAY('now') - JULIANDAY(Flights.EndTime))AS INTEGER) &gt;= 180
  GROUP BY Registration
  ORDER BY Flights.EndTime
  </code></pre>
  <p>The problem is that the Flights.EndTime is written in ascending order and the query thus looks at the first Flights.EndTime entry instead of the last one.
  Is it possible to query the database and retrieve the list of aircraft that were not seen for 180 days or more?</p>