B
B
bernex2015-07-11 14:28:40
MySQL
bernex, 2015-07-11 14:28:40

What is the best way to organize tags in a database?

Task: there are users, tasks these tables can have tags.
You can make 2 tables with tags and tag links.
You can make a view to get the view:
id, name, tags separated by commas.
But is it possible to make a query like:
SELECT * FROM users_with_tags WHERE tags IN ('best', 'new')
to select users with tags?
I would like to make work with tags inside and convenient outside.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-11
Protko @Fesor

so...let's figure it out. Can users have tags too? Or tags only for tasks?
And so there are two options:
- normalize everything, tags in a separate table, link through links. Flexible and a little more difficult.
- store tags in an array for tasks, postgresql does. It's simple, fast, and it will only be difficult to organize an autocomplete and fetch a list of existing tags. In this scenario, the first option is more efficient.

D
Dmitry Bay, 2015-07-11
@kawabanga

Do through a many-to-many relationship. (table tags and links).
In one of the projects, it was necessary to make quick selections by tags, and it turned out that it was faster to do them through such a connection. (when there is a table of tags and a table of links).
Alternatively, mysql has such a function - find_in_set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question