我有一个具有以下结构和数据的mysql表。我想在任何ID上显示最后插入的记录。从MySQL表中获取最新的更新值
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
我想要得到这样的结果:
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
Dipesh Parmer's和aaaaaa123456789的回答将返回此数据集的预期结果。但如果数据发生变化(不低估他们的支持),它可能会返回错误的值。检查小提琴中已更改的数据集(交换了lc_timestamp前2个值)。这是我今天能做的最好的。进一步了解团队是如何工作的。这[问题](http://stackoverflow.com/questions/1425240/select-rows-with-maximum-column-value-group-by-another-column)描述了一点。 – chandimak 2013-03-01 12:07:01