How would I structure database the best?

What is the best structure of database for activity (news) feed?

  • What is the best structure of database for activity (news) feed? Eg. A user is subscribed to activity of a group, actgivity of another user, and certain tag. HJow shall I organize database structure to show these activities to the user? I have the following structure of databases: User: id first_name last_name Group: id user_id (FK - User) name GroupTopic: id user_id (FK - User) group_id (FK - Group) name message Tag: id user_id (FK - User) name GroupTag group_id (FK - Group) tag_id (FK - Tag) GroupFollower: group_id (FK - Group) user_id (FK - User) TagFollower: tag_id (FK - Tag) user_id (FK - User) Eg I am subscribed to a group and a tag, so there is my user_id in tables GroupFollower and TagFollower. So, how in this case I will track that a new group that appeared in tag (GroupTag table) and that in group which I subscribed to new topic appeared (GroupTopic table). I assume there must be some Activity table Activity: id user_id (FK - User) - user who made changes ..... But what happens next? What should be fields and requests to get all new in groups, tags, etc.?

  • Answer:

    Include a timestamp in the activities. Add a column to the users table 'last_checked'.select *from activitieswhere timestamp < ( select last_checked from users where user_id = @this_user);update usersset last_checked = @nowwhere user_id = @this_user;

Michael Tepfer at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.