Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 570995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:27:38+00:00 2026-05-13T13:27:38+00:00

I have my tags desinged like this in my database: Table: Item Columns: ItemID,

  • 0

I have my tags desinged like this in my database:

Table: Item 
Columns: ItemID, Title, Content 

Table: Tag 
Columns: TagID, Title 

Table: ItemTag 
Columns: ItemID, TagID



//example -- this is the right sidebar of stackoverflow
c# × 59279
sql × 14885
asp.net-mvc × 9123
linq × 4337
tags × 339

if I wanted to know the count of each tag such as how stackoverflow counts their tags how would I do it? What kind of query would I perform. I am open to both regular sql and linq

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:27:38+00:00Added an answer on May 13, 2026 at 1:27 pm

    Add another column in the table Tag that work as counter. When you add or remove a tag from an item you update the counter (in other words, when add a row on Itemtag increment the counter on Tag table, when remove decrement the counter)

    add tag to item:

    INSERT INTO Itemtag (itemid,tagid) VALUES ('$itemid','$tagid');
    UPDATE Tag SET counter=counter+1 WHERE tagid='$tagid';
    

    remove tag from item

    DELETE FROM Itemtag WHERE itemid='$itemid' AND tagid='$tagid';
    UPDATE Tag SET counter=counter-1 WHERE tagid='$tagid';
    

    retrieve item tags with counter

    SELECT t.title, t.counter FROM Itemtag AS it JOIN Tag AS t ON t.idtag=it.tagid 
    WHERE it.itemid='$itemid'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with 6 columns containing HTML content with some markups in
I do have tags like this search100 web250 seo36 analytics5060 traffic8000 web2.0 I want
I have a django project with 2 apps like this: ## tags app, models.py
I have a tags model that I'd like to be polymorphic, but I don't
In my repository, I have created tags using the following commands. git tag v1.0.0
On a blog detail page, I have a tags section. The html looks like:
I have a table : tags(tagname,entryid,stamp) and i want to make a section for
Lets say I have this class (simplified): class Tag (...): children = models.ManyToManyField(null=True, symmetrical=False)
I've designed a multilingual web site and some values in database have a tag
Suppose I have a database which contains blog posts which have tags and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.