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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:01:26+00:00 2026-06-13T03:01:26+00:00

So I have a table like this: Item Number Collection Items in Collection 1234

  • 0

So I have a table like this:

  Item Number     Collection       Items in Collection 
    1234         Madison Park                       
    2345         Madison Park                       
    3456         Madison Park                       
    6747         Belcaro                            
    5678         Belcaro                            

What I need is this:

  Item Number     Collection       Items in Collection 
    1234         Madison Park        1234, 2345, 3456     
    2345         Madison Park        1234, 2345, 3456     
    3456         Madison Park        1234, 2345, 3456     
    6747         Belcaro             6747, 5678           
    5678         Belcaro             6747, 5678           

Or better yet, this:

  Item Number     Collection       Items in Collection 
    1234         Madison Park        2345, 3456           
    2345         Madison Park        1234, 3456           
    3456         Madison Park        1234, 2345           
    6747         Belcaro             5678                 
    5678         Belcaro             6747                 

This isn’t my preferred method of getting the result, but due to client specifications the table needs to be set up this way. Also, it needs to be done through a MySQL Workbench Query. I’ve tried every variation of CONCAT_WS and GROUP_CONCAT I can think of but haven’t managed to come up with a solution. Group_Concat returns the results I want, but then it groups the collections, which won’t work. Ideas?

  • 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-13T03:01:27+00:00Added an answer on June 13, 2026 at 3:01 am

    Try joining the table to itself on the grouped collection value. GROUP_CONCAT() will return a string, so you can REPLACE() the current rows’ item_number on it, however you don’t know exactly where the comma will be, so although it is a hack you can use SEPARATOR ' ' and then REPLACE() the item_number from the current row, replace occurrences of two spaces with one (the item_number was in the middle), TRIM() it (the item_number was on the end) and then replace the single spaces with a comma followed by a space:

    SELECT i.item_number,
            i.collection,
            REPLACE(REPLACE(TRIM(REPLACE(g.items, i.item_number, '')), '  ', ' '), ' ', ', ') AS collection_items
    FROM    item_table i
            INNER JOIN 
            (
                SELECT collection,
                        GROUP_CONCAT(item_number SEPARATOR ' ') AS items
                FROM item_table
                GROUP BY collection
            ) g ON g.collection = i.collection
    

    I tested this locally and got your expected results.

    SQLFiddle Demo

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

Sidebar

Related Questions

I have a table Item with a number of related items, like so: ID
I have a bill of materials table that is set up like this: item
I have a stock transaction table like this: StockID Item TransDate TranType BatchNo Qty
I have a table like this: create table foo ( a number, b number
I have a query that returns items like this Item -- Code -- Thing
I have a table like this id item user slot I want the SLOT
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy
I have a table like this : +-------+------------+------+-----+---------+-------+ | Field | Type | Null
I have a table like this: ID country ------------- 1 US 2 Japan 3

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.