下面是我的数据库结构
User
id name
1 John
2 Doe
3 Smitt
Post
id user_id text
1 1 Hello
2 1 World
3 2 How are you?
4 3 Whatsup!
5 3 High five!
Comment
id post_id text created_at
1 1 Comment on Hello 2019-12-01
2 1 Another comment on Hello 2019-12-02
3 2 Comment on World 2019-12-03
4 1 Latest comment on Hello 2019-12-04
5 1 Some comment 2019-12-05
6 5 Five highs! 2019-12-06
7 4 Same old,same old! 2019-12-07
如何基于MySQL中的Comment
获取仅包含一个MAX(created_at)
记录的用户列表,如下所示?
Result
id name comment_text created_at
1 John Some comment 2019-12-05
2 Doe NULL NULL
3 Smitt Same old,same old! 2019-12-07
条件::由于另一个用例,流程必须从User
表转到Comment
表,而不是相反!