I have a table with 3 fields:
ID(not unique, not primary key)timestampmarker
I want to get the last entry for every distinct ID, but when I doSELECT ID, max(timestamp) from table GROUP BY ID
the marker field is wrong.
I have another table with the following fields:
ID(unique, primary key)latlng
I would like to perform the same query but with the lat and lng fields as well, but since I can’t do the first step, I don’t know what kind of query should I use. I’ve been trying with no success.
Could someone point me in the right direction? Thanks a lot.
Having an
IDcolumn that is not unique sounds “unexpected”, but this one should get you the expected rows:The second group by will make sure that you only get one row in case there are more records for the same
idandtimestamp.Update: Edited query to join
t2.Use
LEFT JOINin case there areids int1that do not exist int2.latandlngwould then beNULLfor that rows.