Reputation: 5169
I'm trying to create a small Web App to categorize certain type of YouTube videos, when users submits a video they will choose what categories this video falls under and they will tag it with ready-made tags, for example:
Video one - Category: Ad - Tags: cute, funny, has animal in it.
I'm trying to sketch my Database for that (I'm using MySQL), so far I have two ideas.
Idea 1:
Table Videos with ID
and Category
columns, another table Tags with ID
and Tag
columns while Videos.ID
and Tags.ID
are linked together. So when the user tries to filter search results by tags, the query will have more conditions (AND Tag = 'something' AND Tag = 'other thing'
).
Idea 2:
One table Videos with Category
and Tags
columns, tags are stored as a string separated by commas, when the user tries to filter search results by tags, the query will more conditions (AND Tags LIKE '%something%' AND Tags LIKE '% other thing%
).
So the question is: Is there any better method? I already think that the 1st one is wasteful (Each video might have up to 40 ready-made tags) and the 2nd one is clumsy. If not, which one do you think is better?
Upvotes: 2
Views: 172
Reputation: 34
Idea 1 looks good. Creating a separate table for storing tags helps in selection.
Upvotes: 0
Reputation: 14941
Creating a additional table linking video id
and tag id
together is the correct solution. Filtering is done by creating additional INNER JOIN
conditions. A comma separated list just won't do - it drastically limits your selection and query possibilities.
Upvotes: 3