0
我有一个典型的MySQL数据库为此设置:张贴表,用户表,评论表。通过新评论获得我评论过的帖子?
什么是最好的方式来查询诸如“我发表评论,自从我上次评论以来有新评论”的帖子?我无法到达了如何合并其他用户comment_timestamp比我comment_timestamp条件高到下面的查询:
我有大约
SELECT * FROM posts
WHERE posts.id IN
(SELECT DISTINCT posts.id FROM posts,users,comments WHERE comments.post_id = post.id AND comments.user_id = $current_user_id) AND .. something to filter only comments where timestamp is greater than mine
我知道我可以遍历一组和过滤外界的MySQL,但我希望尽可能在MySQL中完成。我知道可能有一个更好的方式与加入要做到这一点,但我失去了对如何移动comment_timestamp为“我的”最后评论的两部分之间加入
user table
-----
id
posts table
------
id
user_id
comments table
-------
id
user_id
post_id
comment_timestamp
请在您的问题中提供一些数据。 –
输入以及输出数据。 –