Quantcast
Channel: Database design and SQL query for the activity feed? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Database design and SQL query for the activity feed?

$
0
0

I want to build some activity feed similar to facebook. Before I ask my question, I want to explain my mySQL database design. I have a users table, ie.

user_id     name     other columnsuserA       -           -userB       -           -userC       -           -userD       -           -

The users can follow each other, and here is the table called 'followers'

id      user_id         follower_id1        userA            userB2        userD            userB3        userB            userA---

As we see, in above table, userB is following userA and userD.

Now my question is, when ANY of the user in the user_id to whom userB is following, does an activity, should be notified. Should i make another table, lets say, 'activity', something like:

user_id     activity_type   activity_link  activity_date  userA           noteuserB           photouserC           noteuserD           photo

Question 1: Do I need to make additional table (shown above) to store the activities or it can be done without that?

Question 2: As userB in following only userA and userD, therefore userB is concerned only with the users he is following, how can i build the sql query for that? sth like:

 Select * from activity where user_id exists in user_id in followers table where follower_id = userB 

(This is my idea, can you help me building SQL query)

Thanks for reading this long question and possible help.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images