我正在构建一个通知系统,用户可以看到他关注的新帖子的数量。在本例中,我是用户7
我有两张桌子
社区
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
我想要的是将我关注并发布的每个用户的post status
更新为1
这只会更新所有内容
update posts as p
inner join community as c on
c.id_follower = 7
set p.status=1
在这种情况下,它应该返回2行posts table updated (2,3)
发布于 2018-02-23 04:13:08
您应该为与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
https://stackoverflow.com/questions/48936272
复制相似问题