newest records from table by id

28 views
Skip to first unread message

Karel Uhlík

unread,
Mar 6, 2013, 11:54:24 AM3/6/13
to not...@googlegroups.com
Hi,
I would like to ask someone for help with following SQL. Is there possibility to use NotORM for selecting newest records from table by gps_id ?

SELECT t1.gps_id, t1.machine_id, t1.lng, t1.lat, t1.date, machine.name
FROM gps t1
   LEFT JOIN machine ON t1.machine_id = machine.id
   INNER JOIN (
      SELECT gps_id, MAX(date) AS date FROM gps GROUP BY gps_id
   ) t2 ON (t1.gps_id = t2.gps_id AND t1.date = t2.date)

Thank you in advance


Karel Uhlik
Reply all
Reply to author
Forward
0 new messages