Good day, friends. There is a need to deduce from the database values ​​from a specific column. However, this should be done in such a way that the sample does not contain duplicate values.

Now I deduce such request:

"SELECT * FROM questions GROUP BY tags ORDER BY views DESC LIMIT 50" 

That is, I display unique values ​​from the tags column. And everything would be fine, but something like this “label 1, label 2, label 3” is written in this column (With PHP, I break this line into 3 different words, but this is not about that now). The problem is that some values ​​match on different lines, for example, "label 4, label 2, label 6", "label 18, label 3, label 10", etc. Actually, you need to make a selection in such a way that matches from different lines do not fit into the sample, somehow ...

That is, if “label 2” is already in the sample, then let the value “label 4, label 2, label 8” fit into the sample only “label 4, label 8”

    1 answer 1

    The only correct option is to put in order the data, now it is no good. You need two tables, first a tag table:

     id int primary key, title varchar(255) -- возможно какие-то ещё данные (id юзера, который добавил тег, -- время создания и т.д.) 

    And the question tag table:

     id int primary key, question_id int (index), tag_id int (index) 
    • Yes, it will be the best solution and simple in terms of output. Thank you very much! They stuck their noses at banal truths)) - G_Java