如何从MySQL中获取最新日期的行


How to fetch the row from MySQL having latest date

我有一个表"poems",包含字段"dated"、"content"等。

我想获取最近日期字段的内容。

$sql="select content, max(dated) as latestDate from poem";

这不起作用。

如果只需要一行,请使用order bylimit:

select p.*
from poem p
order by dated desc
limit 1;

如果您想要所有具有最近日期的行:

select p.*
from poem p
where p.dated = (select max(dated) from poem);

您只需在日期前订购

SELECT * FROM TABLENAME ORDER BY DATE DESC