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

  • Home
  • SEARCH
  • 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 389677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:53:25+00:00 2026-05-12T15:53:25+00:00

How is the best way to do a ‘running total’ system like the tags

  • 0

How is the best way to do a ‘running total’ system like the tags search on stackoverflow? If I click on ‘php’ for example, its show the total amount of items on ‘each’ other tags, and its very fast. How can I do this in php with mysql?

  • 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-12T15:53:25+00:00Added an answer on May 12, 2026 at 3:53 pm

    It’s a query that “looks” like that

    SELECT T2.Tag, COUNT(*)
    FROM SO_Posts P1
    JOIN Post_Tags T1 ON P.PostId = T1.PostId
    JOIN Post_Tags T2 ON P.PostId = T2.PostId
    GROUP BY T2.Tag
    WHERE T1.Tag = 'PHP'
    ORDER BY COUNT(*) DESC
    

    This query makes the plausible assumption that the Posts (Questions) on SO are stored in two tables;
    SO_Posts, containing one record per Post, and holding info such as a PostId (Primary Key), the question itself, the date, the title etc.
    and
    Post_Tags which associates a given Post (by its Post_Id) with a Tag (or more likely a TagId since tags ought to be normalized, but that’s a detail). For a given Post, there are as many records in Post_Tags as there are different tags attached to the post.
    Note: in effect the structure of the SO Posts database is more complicated, with various tables for storing comments, replies etc. but with regards to the Post-to-Tag relationship, this two-table layout (or more likely a 3 tables layout allowing to have a tagId in the Post_Tags rather than the tag itself) captures the essence of how it is possible, easy and fast (provided the right indexes) to show these filtered agregate counts.

    The idea is to find all PostIDs associated with the targeted tag (here ‘PHP’) (looked-up in “T1”) and then to aggregate all the Posts (in “T2”), by Tag.

    Note that the main table SO_Posts is not necessary here, but it would likely be part of the query, for example to allow adding extra criteria such as say the Post status (not being closed…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the best way to explain is with example so: this is the model public
The best way I can think of to ask this is by example... In
The best way to do this? Tried things like that: public String FormatColumnName(String columnName)
Best way to illustrate my question is with this example code: class Item {}
the best way center 2 divs inner div. Like this 1 2 3 4
what's the best way to read all my aspx files in a directory, search
What is the best way to prevent the browser from caching images in PHP?
Best way i can demonstrate is by example, if you go here and move
The best way to phrase the question is with an example. If you look
The best way to take a string that is formated like... YYYY-MM-DD and make

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.