开发者

MySQL last instance of in a group

开发者 https://www.devze.com 2023-02-16 15:01 出处:网络
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.

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

精彩评论

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