开发者

MySQL last instance of in a group

I have a mysql database table that contains multiple user photos. I am trying to write a query that will group by the subscriber_id but grab the latest entry.

For example:

A subscriber uploaded 4 photos. I need to group by the subscriber id but grab the latest photo uploaded. Is there anyway to do 开发者_运维问答this?


SELECT subscriber_id, MAX(photo_id)
FROM user_photos
GROUP BY subscriber_id


select photoId from photos where subscriber_id = ? order by date_added desc limit 1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜