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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:54:24+00:00 2026-06-05T02:54:24+00:00

I have a 3 table tag system, topics, tags and tagtopic. I now want

  • 0

I have a 3 table tag system, topics, tags and tagtopic.

I now want to display the various tags for each topic as I display the topic. Since there are multiple tags for one topic, when I do the query below, I get multiple rows and the topic displays multiple times, once for each row. I don’t think I can use a groupby as I’m not doing anything mathematical with the columns. What I really would like would be for each topic, display the topic and then a list of tags for a post such as (for Siri), ‘iphone,smartphone,Siri’.
tables:

topics
id | name |userid
tags
id | topicid | topicname
tagtopic
id | tagid | topicid '

$sql = "SELECT * FROM `topics` t
LEFT JOIN `tagtopic` tagtopic
on t.id = tagtopic.topicid
WHERE t.id= '12'";

Should mention that display is done with while($row = mysql_fetch_array($res)) so that it is displaying the rows of the recordset. I would like it to display the topic once, but since there are multiple rows created for the tags, it is displaying multiple times.

Do I have to give up on the join and do a subquery? Thanks for any suggestions.

  • 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-05T02:54:26+00:00Added an answer on June 5, 2026 at 2:54 am

    You can do a GROUP_CONCAT which will put all the tags into a single field separated by a comma.

    SELECT GROUP_CONCAT(tt.tagid) FROM topics t
    JOIN tagtopic tt ON tt.topicid = t.topicid
    WHERE t.id=12
    GROUP BY t.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an objects, tags, and tag_relationships table. Objects and tags each have an
I'm building an article system, and each article will have one more Tags associated
I implemented a many-to-many tag system, and now I want to peform a full
I am trying to make 3 table tags system. I have 3 table in
If I have a tag system like Stackoverflow. I can add tags, save and
I have a system right now that stores products and tags that are associated
I have the following setup: Table: Question QuestionId Table: QuestionTag QuestionId TagId Table: Tag
Say I have a table named items : id int(11) ... tag int(11) And
I have the Demo Table which I can click on the cell(td tag) and
I have a mysql table that have several records linked to one particular tag.

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.