D
D
Dmitry Kuzmin2016-09-13 12:31:31
MySQL
Dmitry Kuzmin, 2016-09-13 12:31:31

How to select the maximum date in MYSQL with one select?

There is a table in which there is a field type datetime and timestamp. I need to select the maximum time (datetime type) value. I write:
select info, MAX(date) from table
It gives me the maximum date, everything is OK, but the value of info is from the first line in the result of the selection.
The design works correctly:

Select * from table where date IN (SELECT MAX(`date`) as `time` FROM `table`)

Do I understand correctly that only through a nested select can this be done? Ie in one it is impossible.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2016-09-13
@Dimkaa

you understand correctly: if you need to get all the records with the maximum date, then you can’t do without a subquery.
PS Your question is at odds with the code.

M
Melkij, 2016-09-13
@melkij

One line?
If all rows have the same maximum date, then yes, a subquery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question