mysql评论回复_如何在MYSQL中进行评论回复查询?

我正在评论回复(仅限一个级别)功能.所有评论都可以有多少回复,但没有回复可以进一步回复.

所以我的数据库表结构如下所示

Id ParentId Comment

1 0 this is come sample comment text

2 0 this is come sample comment text

3 0 this is come sample comment text

4 1 this is come sample comment text

5 0 this is come sample comment text

6 3 this is come sample comment text

7 1 this is come sample comment text

在上述结构中,有1个(有2个回复)和3个(1个回复)有回复.因此,要获取注释及其回复,一个简单的方法是首先获取所有具有ParentId为0的注释,然后通过运行while循环获取该特定commentId的所有回复.但是,如果我在特定记录上有大约200条评论,那似乎会运行数百个查询.

所以我想创建一个查询,它将按顺序获取带有回复的注释,如下所示;

Id ParentId Comment

1 0 this is come sample comment text

4 1 this is come sample comment text

7 1 this is come sample comment text

2 0 this is come sample comment text

3 0 this is come sample comment text

6 3 this is come sample comment text

5 0 this is come sample comment text

我的评论表中也有一个评论日期列,如果有人想在评论查询中使用它.

最后,我想通过使用一个单独的mysql查询来获取所有注释及其回复.请告诉我怎么做?

谢谢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值