mysql 查询
有这样一个需求
文章(articles) | |||
---|---|---|---|
文章 id | 创建人 id | 最佳回答人 id | 是否公开 |
id | creator_id | answser_id | is_open |
文章 - 关注者(多对多)(followers) | |
---|---|
文章 id | 关注人 id |
article_id | follower_id |
当公开时所有人可见
当不公开时,创建人,最佳回答人,文章关注者可见
这种的查询语句应该怎么写
select * from a join b on a.id = b.article_id where a.is_open = 1 or (a.is_open=0 and (a.creator_id=$uid or a.answer_id=$uid or b.follower_id=$uid))