MySQL LEFT JOIN using MAX & GROUP BY on joined table?

后端 未结 3 1158
天涯浪人
天涯浪人 2021-01-31 04:37

I\'ve got two tables (members and activities) and I\'m trying to query the members with the latest activity for each member. I\'ve got it working with two queries (one to get t

3条回答
  •  天涯浪人
    2021-01-31 05:33

    Select max(a.id), m.name, a.activity_code, a.activity_timestamp, a.activity_description
    From members m
         Left join
         activities a on a.member_id=m.id
    Group by  m.name, a.activity_code, a.activity_timestamp, a.activity_description
    

提交回复
热议问题