如何从下表中选择用户朋友的帖子?

时间:2015-12-08 05:48:05

标签: mysql sql

please check the screenshot on the below link for the tables http://oi65.tinypic.com/jb61d2.jpg

  

表1:帖子
表2:朋友

我想在网站上显示用户朋友的帖子(比如 userId=3 ),那么我应该使用两个表格查询吗?
如果 status=1

,则user_one_id和user_two_id是朋友

1 个答案:

答案 0 :(得分:0)

SELECT * 
FROM posts p JOIN friends f on p.userId=f.user_one_id OR p.userId=f.user_two_id 
WHERE userId=3