【发布时间】:2017-04-08 15:28:11
【问题描述】:
这个问题取决于我之前的问题: 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”的所有帖子,因为考虑到我之前的问题,我正在关注他们。
非常感谢你,对不起我的英语不好:)
【问题讨论】:
-
您使用的是哪个数据库?您标记了 mysql 和 sql-server。
-
如果您之前的问题是关于 MySQL 的,那么我认为这个也是。请不要在您的问题上添加多余的标签。
-
对不起...我正在使用 mysql
-
我看到的一个问题是您为多个表提供了相同的别名。除此之外,您只需要使用 follower_user 对表(名称?)进行连接。
-
好的,我更新了我的问题。表名是“tbl_user_follow”。我是 sql 新手 :) 如果你知道这个查询,你能回答吗?