I have a database that contains two tables:
- entries
- tags
The entries table contains posts that each have one or more tags. The problem is, each post can have any number of tags. In other words, I can’t have a ‘tag1’, ‘tag2’, etc. column and do a LEFT JOIN.
How should I set up entries so that each post can have any number of tags?
You need a mapping table.
Create a table called
entries_tagsthat contains two columns:entry_idandtag_id, with a multi-key on both entries.This is called a many-to-many relationship.