选择“其他表的多行中具有条件的行”


select rows with condition in multi rows of other table

我想显示用户关注的所有帖子。我有两个表是post_tbfollow_tb,链接列是post_tb.user_idfollow_tb.follower_id.

如果我在表格上显示所有帖子,我会得到这样的 SQL 条件

"select * from post_tb order by date_time desc;"

这是 sql 条件,只显示他们关注的人.

"select * from post_tb where user_id in(select follow_to_id from follow_tb where follow_tb.follower_id='$sessionid') order by date_time des;"

它们都是工作,但是当记录数增加时,第二个 sql 会变慢。有更好的方法吗?
谢谢你的回答

子查询很慢,而是使用join

select * from post_tb  p
join follow_tb f ON(p.user_id = f.follow_to_id )
where f.follower_id='$sessionid'
order by date_time desc;