【发布时间】:2011-02-05 07:57:32
【问题描述】:
我想建立一些类似于 facebook 的活动源。在我提出问题之前,我想解释一下我的 mySQL 数据库设计。我有一个用户表,即。
user_id name other columns
userA - -
userB - -
userC - -
userD - -
用户可以互相关注,这里是名为'followers'的表格
id user_id follower_id
1 userA userB
2 userD userB
3 userB userA
-
-
-
如我们所见,在上表中,userB 正在关注 userA 和 userD。
现在我的问题是,当 userB 关注的 user_id 中的任何用户进行活动时,应该通知。我应该再做一张桌子吗,比如说“活动”,比如:
user_id activity_type activity_link activity_date
userA note
userB photo
userC note
userD photo
问题 1:我是否需要制作额外的表格(如上所示)来存储活动,或者不需要它也可以完成?
问题 2:由于 userB 只关注 userA 和 userD,因此 userB 只关心他关注的用户,我该如何为此构建 sql 查询?比如:
Select * from activity where user_id exists in user_id in followers table where follower_id = userB
(这是我的想法,你能帮我构建 SQL 查询吗)
感谢您阅读这个冗长的问题和可能的帮助。
【问题讨论】:
标签: sql database-design