gpt4 book ai didi

php - 多对多查询

转载 作者:行者123 更新时间:2023-11-30 23:09:30 25 4
gpt4 key购买 nike

我有以下表格:

用户(ID、姓名、电子邮件)关注 (id, follower_id, following_id)post (id, user_id, title, body)

现在关注意味着我 (user_id = 23) 关注另一个用户 (user_id = 12),也许还有几个。

我想做一个查询,它可以显示我关注的所有人发布的所有帖子。

单个查询是否可行?

最佳答案

当然可以,但是请确保您有适当的索引,否则可能需要一段时间!

SELECT `user`.`id` AS `user_id`, `user`.`name`, `post`.`id` AS `post_id`, `post`.`title`, `post`.`body`
FROM `follow`
JOIN `user` ON `user`.`id`=`follow`.`following_id`
JOIN `post` ON `post`.`something...` # You're missing an "author" field in your posts table!
WHERE `follow`.`following_id` = 23

关于php - 多对多查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20454974/

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