elan
elan

Reputation: 5

MYSQL select the lastest time of each date

Hi I have a mysql table and it contained something like this

HISTORY
===================
2013-07-01 16:23:43
2013-07-01 17:32:11
2013-07-01 20:44:22
2013-07-02 23:65:12
2013-07-03 10:23:32
2013:07-03 12:54:02
and etc........

for example the first three row are 2013-07-01 16:23:43, 2013-07-01 17:32:11, and 2013-07-01 20:44:22 and the lastest date in this history is 2013-07-01 20:44:22

So what I really want is.. Is there any way that I could make a selection that have a result like this

HISTORY
===================
2013-07-01 20:44:22
2013-07-02 23:65:12
2013:07-03 12:54:02
etc....

Thank You

Upvotes: 0

Views: 101

Answers (2)

ASPMaker
ASPMaker

Reputation: 303

Maybe it can be like that;

select Max(history) as MyMaxTimeForADay from MyTime t1 group by Date(t1.history);

you can see how is work at this link : http://sqlfiddle.com/#!2/12be2/2/0

Upvotes: 0

Meherzad
Meherzad

Reputation: 8553

Try this query

select date(history) as dat,
max(history)
from table1
group by dat

SQL FIDDLE

|                         DAT |                MAX(HISTORY) |
-------------------------------------------------------------
| July, 01 2013 00:00:00+0000 | July, 01 2013 20:44:22+0000 |
| July, 02 2013 00:00:00+0000 | July, 02 2013 23:59:12+0000 |
| July, 03 2013 00:00:00+0000 | July, 03 2013 12:54:02+0000 |

Upvotes: 4

Related Questions