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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:35+00:00 2026-06-13T00:51:35+00:00

I am trying to implement a tag system for items. The tags are contained

  • 0

I am trying to implement a tag system for items. The tags are contained in a table called tags and I have another table tagitem that links items to tags. An item can have multiple tags. When I display the item, I would like to list all the tags. My question is, is there any way to do this with one query? If I join the items result to the tags table, either I get multiple records for one item (corresponding to the multiple tags) or if I include a group by tag, I get one record but only the first tag.

The other way would be to do a second query just to get the tags but that seems inefficient.

Item table
Id | name

Tag table
Id | tag

Tagitem table
Id|itemid|tagid

Php

$sql = "select i.*,ti.*,t.*
FROM 'items' i
LEFT JOIN 'tagitem' ti
ON i.id=ti.itemid
LEFT JOIN  'tag' t
On ti.tagid=t.id
WHERE i.id='2'";

//returns multiple records

$sql.="group by i.id";

//returns only first tag

Thx 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-13T00:51:36+00:00Added an answer on June 13, 2026 at 12:51 am

    Try GROUP_CONCAT.

    You should be able to select your tags as a subquery and group them together to form an array.

    SELECT
        Item.name,
        GROUP_CONCAT (Tags.tag SEPERATOR ',') AS tags
    FROM
        Item
        LEFT JOIN Tagitem ON Tagitem.itemid = Item.Id
        LEFT JOIN Tag ON Tagitem.tagus = Tag.Id
    WHERE
        Item.Id = 2
    

    Give that a shot and let me know what happens. I’m guessing at the table structure a bit, so it may require some tweaking.

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

Sidebar

Related Questions

I'm trying to implement a 3 table item tagging system Table: Item Columns: ItemID
I have a form where I am trying to implement a tag system. It
I am trying to build a little system that would assign specific tags to
I'm trying to implement a basic tagging system with hibernate. The problem is that
I'm trying to implement custom suggestions for qsb. I have added CREATE TABLE IF
I am trying to implement a tag cloud using acts_as_taggable. I already have my
I have a system that uses tags to categorize content similar to the way
I'm trying to implement a feature similar to StackOverflow's tag feature. That a user
Im trying to implement small project where people can set tags for certain items
I have a CMS system that stores data across tables like this: Entries Table

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.