This question already has an answer here:
I need to get all distinct value from db according to their recent/last entryModTime
.
For your understanding
id entry_modtime
3 13-12-1977
3 14-12-1977
4 13-12-1977
5 13-12-1977
2 13-12-1977
3 15-12-1977
In the above table id
field is not primary. I need get all data from that table so the output should be,
3 15-12-1977
4 13-12-1977
5 13-12-1977
2 13-12-1977
</div>
You can group
around your id
and select the highest date for every id
with max()
select id, max(entry_modtime) as latest_entry_modtime
from your_table
group by id
select id, max(entry_modtime)
from your_table
group by id