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 9062251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:41:29+00:00 2026-06-16T15:41:29+00:00

I have two tables, one called Tags , the other called Posts_Tags for a

  • 0

I have two tables, one called Tags, the other called Posts_Tags for a many-to-many relationship. The Posts_Tags contains two columns, postid and tagid. The Tags database also contains an id column, which corresponds to the tagid in the joint table.

I’d like to get a list of tag names to display to the user, ordered by the number of times they are used. Using this information, I’ve constructed a query which joins the two tables together:

SELECT Tags.name FROM `Tags` LEFT JOIN `Posts_Tags` ON Tags.id = Posts_Tags.tagid

This gets me a list of tag names, but obviously, it doesn’t do much more than just selecting data purely from the Tags table. I know I need to add an ORDER BY clause somewhere (and possibly a GROUP BY, but I’m not sure how to construct the query.

What should I add to this query to successfully sort my results by the number of posts each tag is used in?

  • 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-06-16T15:41:30+00:00Added an answer on June 16, 2026 at 3:41 pm

    Use Group By To count the number of times each tag is used. This assumes your tag names are unique, if not you’ll want to group on the id instead.

    Select
      t.Name,
      Count(*) as TagUse
    From
      Tags t
        Left Join
      Post_Tags p
        On t.Id = p.TagID
    Group By
      t.Name
    Order By
      TagUse Desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables one called fs_note the other called dumy_fs_note I created after
I have two tables connected with one to many relationship. Parent Table is a
I have two tables: one called Projects, and another called Documents (projects has many
I have two tables one called details and the other called c_details. Both tables
I have two tables on my database. One called room and another is called
I have two tables having 1 to 1 relationship. One table called Person and
I have two tables. One table is called Occurrence that contains the following: OccurrenceID
I have two tables, one called calendars and the other one called events .
I have two tables, one table is called queuelist and the other is call
I have two tables with a many-to-one relationship. (Oracle) **Table: PARENT** Field: A (PK)

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.