Reputation: 11
I've gotten far enough where I realize I need a relationship between two tables.
I've got everything working, except for this scenario:
Let's say one table is called "posts," and the other one is called "authors." they both have keys and all that good stuff.
What if a "post" is written by two or more "authors?" I can't seem to figure out how I can make a "post" link to multiple "author" keys.
i.e. PostID | postText | date| etc | authorkey1, authorkey2, authorkey3 ...
I'm extremely sorry if this has been answered before, but I've scoured stackoverflow and other online sources and have not found anything that applies to my scenario.
Upvotes: 1
Views: 357
Reputation: 14165
what if a "post" is written by two or more "authors?"
You will want another table if you can have multiple authors per post.
You can have:
*
authors per post (three tables, Authors/Posts and PostAuthors)I would strongly recommend the third. If you choose the second approach, it will work, but you are going to run into scaling issues. What if you have 3 authors? Or 10?
If you add new columns for each, your table is going to get messy fast. But if your PostAuthors table just contains posts and authors, you can have as many entries in that table as you want.
Upvotes: 1