从MySQL表获取最新的更新值 [英] Get last update values from MySQL table

查看:107
本文介绍了从MySQL表获取最新的更新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构和数据的mysql表。我想在任何ID上显示最后插入的记录。

I have a mysql table with the following structure and data. I want to show last inserted record on any id.

id    lc_counter       lc_timestamp
1     15               2013-03-01 11:54:43
1     13               2013-03-01 11:48:56
10    7                2013-03-01 11:54:43
10    5                2013-03-01 11:48:56
100   5                2013-03-01 11:54:43
100   3                2013-03-01 11:54:43


SELECT inv_id, lc_counter, lc_timestamp 
FROM link_counter 
group by inv_id
order by inv_id asc, lc_timestamp desc

我想得到这个结果:

I want to get this result:

id    lc_counter       lc_timestamp
1     15               2013-03-01 11:54:43
10    7                2013-03-01 11:54:43
100   5                2013-03-01 11:54:43


推荐答案

Select link_counter.lc_counter, MAX(link_counter.lc_timestamp)
 from link_counter group by link_counter.id

这篇关于从MySQL表获取最新的更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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