gpt4 book ai didi

mysql - 根据表 B 中的值从表 A 中选择值?

转载 作者:行者123 更新时间:2023-11-29 01:05:20 25 4
gpt4 key购买 nike

我正在创建一个非常基本的帖子和回复系统,以便更好地了解 MySQL 和 PHP。我有两个表:帖子和评论。

posts(post_id, post_user, timestamp, post_text)
comments(comment_id, post_id, timestamp, comment_text)

我想做的是按照最近回复的帖子排序。所以我需要 SELECT * from ordered by posts by comments.timestamp desc 因为我想按最近的评论而不是原始帖子的时间戳排序。我想不出一个合适的查询。

最佳答案

你可能正在寻找这个

SELECT  p.* 
FROM posts p
INNER JOIN comments c ON c.post_id= p.post_id
ORDER BY c.timestamp desc

关于mysql - 根据表 B 中的值从表 A 中选择值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40212602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com