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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:28:09+00:00 2026-06-14T09:28:09+00:00

I have three tables (many to many relationship): items , items_to_tags , and tags

  • 0

I have three tables (many to many relationship): items, items_to_tags, and tags. The items and tags tables have a unique ID column, and the items_to_tags table has columns item_id and tag_id. Is there a way to select all results from the items and tags tables, but with all results merged into the same record?

For instance, if I have this data:

  • items:

    id     name
    1      'item1'
    2      'item2'
    
  • tags:

    id     name
    1      'tag1'
    2      'tag2'
    3      'tag3'
    
  • items_to_tags:

    item_id    tag_id
    1          1
    1          2
    1          3
    2          3
    

The result of the query should be:

item_id   item_name   tags
1         'item1'     'tag1,tag2,tag3'
  • 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-14T09:28:11+00:00Added an answer on June 14, 2026 at 9:28 am

    You can use the MySQL GROUP_CONCAT():

    select i.id,
      i.name,
      group_concat(t.name SEPARATOR ', ') tags
    from items i
    left join items_to_tags it
      on i.id = it.item_id
    left join tags t
      on it.tag_id = t.id
    group by i.id, i.name
    

    See SQL Fiddle with Demo

    Result:

    | ID |  NAME |             TAGS |
    ---------------------------------
    |  1 | item1 | tag1, tag2, tag3 |
    |  2 | item2 |             tag3 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basicall I have three Tables Users Roles and USerRoles with Many to many Relationship.
I've just gone blank. I have a many to many relationship with three tables.
I have the following three tables: Item Code ItemCode (many to many relationship between
I have three tables: Items , Category and the junction table CategoryItems . Items
I have a database with two tables: tags and items. Each Item has a
I have the following tables items similars items_similars = pivot table items->similars has a
This has been driving me mad. I have three tables: items ID name type
I have two tables with a many-to-one relationship. (Oracle) **Table: PARENT** Field: A (PK)
I have two tables A & B, and B has a many:1 relationship with
I have three tables arranged to make a many to many relationship (Contacts, PurchaseOrder,

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.