Database design and SQL query for the activity feed? -


i want build activity feed similar facebook. before ask question, want explain mysql database design. have users table, ie.

user_id     name     other columns usera       -           - userb       -           - userc       -           - userd       -           - 

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

id      user_id         follower_id 1        usera            userb 2        userd            userb 3        userb            usera - - - 

as see, in above table, userb following usera , userd.

now question is, when of user in user_id whom userb following, activity, should notified. should make table, lets say, 'activity', like:

user_id     activity_type   activity_link  activity_date   usera           note userb           photo userc           note userd           photo 

question 1: need make additional table (shown above) store activities or can done without that?

question 2: userb in following usera , userd, therefore userb concerned users following, how can build sql query that? sth like:

 select * activity user_id exists in user_id in followers table follower_id = userb  

(this idea, can me building sql query)

thanks reading long question , possible help.

yes, need table store activity data. otherwise, have store data elsewhere.

the easiest way write query use join. in case, want activity rows if current user following, can use inner join.

select * activity     join followers f on a.user_id = f.user_id follower_id = 'userb'  

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -