LightNight
LightNight

Reputation: 1625

Select maximum value from database

I have database with row myDate | string

myDate is Date with format YYYY-MM-dd HH:mm:ss. How to select newest date for example, I have:

2011-08-26 14:14:51 

and

2011-09-21 12:25:45

And I need select statement to select last date (2011-09-21 12:25:45). Please help me to write select statement..

Upvotes: 1

Views: 719

Answers (2)

Mark Byers
Mark Byers

Reputation: 837926

Since the dates are stored similar to the ISO 8601 format, the lexicographical order corresponds to the chronological order. So you can just use MAX:

SELECT MAX(myDate) FROM your_table

Upvotes: 4

Arnaud F.
Arnaud F.

Reputation: 8452

This will do the job :

SELECT MAX(myDate) FROM <yourtable>

Upvotes: 2

Related Questions