这个问题取决于我之前的问题: MySql get all rows where id = xxx and where the newest column in other table in row with same id is greater than one
我目前正在使用以下查询来获取所有公开用户的所有帖子:
select p.*
from (select p.*,
(select pp.public_type
from tbl_post_public pp
where pp.post_id = p.post_id
order by date desc
limit 1
) as latest_public
from tbl_post p
order by p.date desc
) p
where latest_public < 80
limit 10;
但不是,我只想获取我在 Instagram 上关注的用户的帖子 我有下表来保存谁正在关注谁:
tbl_user_follow:
id | user | follower_user |
--------------------------------
0 | xxxxx4 | xxxxx1 (<-me) |
1 | xxxxx8 | xxxxx1 (<-me) |
2 | xxxxx3 | xxxxx6 |
所以让我们认为我是用户“xxxxx1”,现在我希望查询查看“xxxxx4”和“xxxxx8”的所有帖子,因为考虑到我之前的问题,我正在关注他们。
非常感谢你,并对我的英语不好感到抱歉:)
最佳答案
您没有指定问题中的表名称或其他表中的字段名称,因此请调整以下内容以匹配这些名称。还将 $user_id 替换为要匹配的 id。
select p1.*
from (select p.*,
(select pp.public_type
from tbl_post_public pp
where pp.post_id = p.post_id
order by date desc
limit 1
) as latest_public
from tbl_post p
order by p.date desc
) p1
JOIN `tbl_user_follow` f
ON f.`user` = p1.`user`
where latest_public < 80
AND (f.`follower_user` = $userID OR f.`user` = $userID)
GROUP BY f.`follower_user`, f.`user`
limit 10;
关于php - 只获取您关注的用户的帖子 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43295925/