Cyrille Belco Ier Cyrille Belco Ier - 1 year ago 83
SQL Question

Select the last entry of each group

I would like the last record in each group member. but with this application, I get rather the first two entries. I feel like Max (time) does not work

SELECT id, latitude, longitude, MAX(temps), vitesse, description, id_recepteur
FROM donneesgps
GROUP BY id_recepteur

Please help

Answer Source

Assuming that temps is time, you want where, not group by:

FROM donneesgps d
WHERE d.temps = (SELECT MAX(d2.temps)
                 FROM donneesgps d2
                 WHERE d2.id_recepteur = d.id_recepteur
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download