gpt4 book ai didi

mysql - 更新内连接 SQL

转载 作者:行者123 更新时间:2023-11-29 07:35:45 25 4
gpt4 key购买 nike

我正在构建一个通知系统,向用户显示他关注的人的新帖子数量。在这种情况下,我是用户 7

我有两张 table

社区

  id_follower   id_followed
7 3
7 5
7 7

帖子

  id_post    id_user_post  post     status
1 3 hi 0
2 5 hello 0
3 9 how are 0

我想要的是将我关注的每个用户的帖子状态更新为1

这只会更新所有内容

    update posts as p
inner join community as c on
c.id_follower = 7
set p.status=1

在这种情况下,它应该返回更新后的 2 行帖子表 (2,3)

最佳答案

你应该添加与id_follower相关的id_follower的条件

 update posts as p
inner join community as c on c.id_follower = 7
and p._id_user_post = c.id_followed
set p.status=1

关于mysql - 更新内连接 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48936272/

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