Many-to-one relationship for tag implementation: how to count how many times a tag is used?

I am experimenting with a tagging system that is many-to-one. My circuit:

elements :

  • item_id
  • Comment

comment tags :

  • item_id
  • tag_id

tags :

  • tag_id
  • tag_name

I read the embed projects on the links below but got stuck. I can insert tags without problem.

How do I get all the tags that were used and how many times it was applied to the _ comment table item ?

http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html

SQL query for product-tag relationship

0


a source to share


2 answers


SELECT t.tag_name, COUNT(*)
FROM tags AS t
    INNER JOIN comment_tags AS c_t ON c_t.tag_id = t.tag_id
GROUP BY c_t.tag_id
ORDER BY t.tag_name;

      



+1


a source


not correct names, but mostly correct syntex



select TagName, count(TagName)
from TagTable
group by TagName

      

0


a source







All Articles