从按日期时间排序的 MySQL 表中获取用户的最后一个条目 [英] Getting the last entry of a user from a MySQL table ordered by DateTime

查看:43
本文介绍了从按日期时间排序的 MySQL 表中获取用户的最后一个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张看起来像这样的桌子:

I have a table who looks something like this:

USERNAME    DATA   DATETIME
Jhon        text1  2010-06-01 16:29:43
Mike        text2  2010-06-01 16:29:22
Silver      text3  2010-05-23 06:19:12
Jhon        text1  2010-02-01 01:02:00

如果我想要Jhon 制作的LAST 条目中的DATA,php 命令是什么???谢谢!

What is the php command if i want the DATA from the LAST entry made by Jhon ??? Thanks!

推荐答案

SELECT data FROM table WHERE username = 'Jhon' ORDER BY datetime DESC LIMIT 1

order by datetime desc"与limit 1"配对为您提供他的最后一个条目.

The "order by datetime desc" paired with "limit 1" gets you his last entry.

这篇关于从按日期时间排序的 MySQL 表中获取用户的最后一个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆