I have a table of log entries that have user_id and datetime.  I'd like to make a query to fetch the most recent of each log entry by user_id.  I can't seem to figure out how to do that...  
The SQL for the query would be something like this:
SELECT * 
FROM table a 
JOIN (SELECT user_id, max(datetime) maxDate
        FROM table
      GROUP BY user_id) b
ON a.user_id = b.user_id AND a.datetime = b.maxDate
Right now I'm doing it with a raw query, but I'd like to use the ORM's methods.
 
     
     
    