选择所有最新的记录不同 [英] SELECT all the newest records distinct
本文介绍了选择所有最新的记录不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的表结构
sn | person_id | image_name |
1 | 1 | abc1.jpb
2 | 1 | aa11.jpg
3 | 11 | dsv.jpg
4 | 11 | dssd.jpg
5 | 11 | sdf.jpg
我需要不同的person_id最新一行如下
I need distinct person_id newest row as following
2 | 1 | aa11.jjpb
5 | 11 | sdf.jpg
IT可能吗?
IT is possible ?
推荐答案
SELECT * FROM table GROUP BY person_id HAVING MAX(sn)
$ b $ 编辑
SELECT f.*
FROM (
SELECT person_id, MAX(sn) as maxval
FROM table GROUP BY person_id
) AS x INNER JOIN table AS f
ON f.person_id = x.person_id AND f.sn = x.maxval;
其中表格是您的表格名称。
where table is your table name.
这篇关于选择所有最新的记录不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文