DEV Community

Khaled Mohamed
Khaled Mohamed

Posted on

How to group multiple different tables for a Many to Many Relation

Hey all, I'm working on a project an I needed some help in the database design.
The project is a platform in which the user can upload a video, write a blog, or create a course.
Each of them has its own table without any connections, but now I need the user to be able to bookmark the content.

The question is, should I make a separate bookmark table for each content type? I was also thinking to make a table called content, that contains only an id field, then each of the content types will add a contentId field as a foreign key (or maybe also a pk), now I can make a bookmarks table containing a userId and a contentId, but I think I'll have a hard time querying the bookmarks and trying to find the data of the content.

Alt Text

I'll really appreciate your opinion on this, thank you all.

Top comments (1)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

For SQLite, I would json_group_array or group_concat.