If i have the below data:
route_name updatedDate route_id
FF 15/06/2012 0:00 22
DD 15/06/2012 0:00 31
FF 16/06/2012 0:00 23
FF 17/06/2012 0:00 24
DD 17/06/2012 0:00 32
DD 17/06/2012 18:00
FF 18/06/2012 0:00
FF 18/06/2012 19:00 40
DD 20/06/2012 0:00 60
I want to run a query where i only see the route_id
based in the latest updatedDate
for the given route_name, so for example for route_name FF
above the route_id
should be 40.
I tried to do this using:
select route_name,route_id,max(updatedDate) from route_de
group by route_name,route_id,updatedDate
having count(*) >= 1
order by route_name
but i get many repeated rows because of the updatedDate field (this is a big table). Can someone please suggest a way to archive the above?