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
精彩评论